Search code examples
c#smtpimapmailkit

Mailkit: unable to send email using "kakao.com" and "daum.net" email accounts


I am able to send emails using the "Gmail/Office365/Outlook/Yahoo/AOL/Naver" account. But unable to send emails using the "kakao.com/daum.net" email accounts.

Kakao.com:
SMTP server: smtp.kakao.com
SMTP port: 465, SSL Required
ID: (Your ID for KakaoMail)
Password: Your password for KakaoMail

daum.net:
SMTP server: smtp.daum.net
SMTP port: 465, Secure connection (SSL) required
ID: (Your ID for DaumMail)
Password: Password to access Daum Mail

public async Task Send()
{
    try
    {
        using (var client = new SmtpClient(new ProtocolLogger(@"D:\PrashantG\Logs.log")))
        {
            var email = new MimeMessage();
            email.From.Add(MailboxAddress.Parse(userName));
            email.To.Add(MailboxAddress.Parse("[email protected]"));
            email.Subject = "Test Email Subject";
            email.Body = new TextPart(TextFormat.Html) { Text = "<h1>Example HTML Message Body</h1>" };

            //await client.ConnectAsync("smtp.kakao.com", 465, SecureSocketOptions.StartTls);
            await client.ConnectAsync("smtp.daum.net", 465, SecureSocketOptions.StartTls);
            client.AuthenticationMechanisms.Remove("XOAUTH2");
            await client.AuthenticateAsync(userName, password);
            client.Send(email);
            client.Disconnect(true);
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

Solution

  • I changed the SecureSocketOptions option "SecureSocketOptions.StartTls" to "SecureSocketOptions.Auto" and working fine.

    public async Task Send()
    {
        try
        {
            using (var client = new SmtpClient(new ProtocolLogger(@"D:\PrashantG\Logs.log")))
            {
                var email = new MimeMessage();
                email.From.Add(MailboxAddress.Parse(userName));
                email.To.Add(MailboxAddress.Parse("[email protected]"));
                email.Subject = "Test Email Subject";
                email.Body = new TextPart(TextFormat.Html) { Text = "<h1>Example HTML Message Body</h1>" };
    
                //await client.ConnectAsync("smtp.kakao.com", 465, SecureSocketOptions.Auto);
                await client.ConnectAsync("smtp.daum.net", 465, SecureSocketOptions.Auto);
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                await client.AuthenticateAsync(userName, password);
                client.Send(email);
                client.Disconnect(true);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }