0

動作していない次のコードがあります。

public static void SendMail(string content, string title, List<string> address)
{
   SmtpClient client = new SmtpClient(Server,Port);
   client.Port = Port;
   client.Host = Server;
   client.EnableSsl = false;
   client.Timeout = 10000;
   client.DeliveryMethod = SmtpDeliveryMethod.Network;
   client.UseDefaultCredentials = false;
   client.Credentials = new System.Net.NetworkCredential(Username, Password);

   foreach(string to in address)
   {
      MailMessage mm = new MailMessage(From, to, title, content);
      mm.BodyEncoding = UTF8Encoding.UTF8;
      mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

      client.Send(mm);
   }
   client.Dispose();
}

次のエラーが表示されます。

メールボックスを利用できません。サーバーの応答は次のとおりです。このサービスを介してメールを送信するには、ユーザー名とパスワードを指定する必要があります

ユーザー名とパスワードを渡していることがわかります。なぜまだこの問題が発生するのですか?

4

1 に答える 1

2

ここでは、gmail サーバーを使用する例を使用しています

MailMessage mail = new MailMessage();
        mail.To.Add(textBox1.Text);

        mail.From = new MailAddress("Yourgmailid");
        mail.Subject = "Email using Gmail";

        string Body = "Hi, this mail is to test sending mail" +
                      "using Gmail in ASP.NET";
        mail.Body = Body;

        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; 
        smtp.Credentials = new System.Net.NetworkCredential
             ("Yourgmailid, "Password");

        smtp.EnableSsl = true;
        smtp.Send(mail);
于 2013-02-08T17:16:58.153 に答える