C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 161 を表示中)
■93053 / )  Re[4]: C#でメール送信ができなくなりました
□投稿者/ ダイチ (3回)-(2019/11/17(Sun) 13:16:32)
ありがとうございます。

以下で作っているのですが、ユーザー認証のところでエラーが出ています。
(UserID,Passwordはもちろん正しいものを入れています)

        public void YM04()
        {
            using (var mySmtpClient = new MailKit.Net.Smtp.SmtpClient())
            {

                var mail = new MimeKit.MimeMessage();
                var builder = new MimeKit.BodyBuilder();

                mail.From.Add(new MimeKit.MailboxAddress("", "xxxxx@yahoo.co.jp"));
                mail.To.Add(new MimeKit.MailboxAddress("", "xxxxx@yahoo.co.jp"));
                mail.Subject = "メールの件名";
                builder.TextBody = "メールの本文です。\n\n以上";
                mail.Body = builder.ToMessageBody();


                mySmtpClient.Connect("smtp.mail.yahoo.co.jp", 465, MailKit.Security.SecureSocketOptions.SslOnConnect);
                mySmtpClient.Authenticate("UserID", "Password");
                
                mySmtpClient.Send(mail);
                mySmtpClient.Disconnect(true);
            }
        }

エラー詳細は、以下ですがやはり認証のところでエラーが出ているのでしょうか。

MailKit.Net.Smtp.SmtpProtocolException
  HResult=0x80131500
  Message=The SMTP server has unexpectedly disconnected.
  Source=MailKit
  スタック トレース:
   場所 MailKit.Net.Smtp.SmtpStream.<ReadAheadAsync>d__39.MoveNext()
   場所 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 MailKit.Net.Smtp.SmtpStream.<ReadResponseAsync>d__46.MoveNext()
   場所 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 MailKit.Net.Smtp.SmtpStream.ReadResponse(CancellationToken cancellationToken)
   場所 MailKit.Net.Smtp.SmtpClient.<SendCommandAsync>d__61.MoveNext()
   場所 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 MailKit.Net.Smtp.SmtpClient.<AuthenticateAsync>d__67.MoveNext()
   場所 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 MailKit.Net.Smtp.SmtpClient.Authenticate(Encoding encoding, ICredentials credentials, CancellationToken cancellationToken)
   場所 MailKit.MailService.Authenticate(Encoding encoding, String userName, String password, CancellationToken cancellationToken)
   場所 MailKit.MailService.Authenticate(String userName, String password, CancellationToken cancellationToken)

返信 編集キー/


管理者用

- Child Tree -