c# ```using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Mail; namespace AppImportantMessage { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private string strMail; public void SetString(string s) { strMail = s; } //正しく動作した場合、textBox1に文字列を入力し、[button1] をクリックすると、label1にテキストボックスに入力した文字列が表示されます private void button1_Click(object sender, EventArgs e) { string textValue = textBox2.Text; //送信者 string senderMail = "xxxxxxxxx@gmail.com"; //宛先 string recipientMail = strMail; //件名 string subject = "お知らせです!"; //本文 string body = textValue; //SmtpClientオブジェクトを作成する System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient(); //SMTPサーバーを指定する sc.Host = "smtp.gmail.com"; //ポート番号を指定する(既定値は25)587 465 sc.Port = 587; //SMTPサーバーに送信する設定にする(既定はNetwork) sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; sc.Credentials = new System.Net.NetworkCredential("送信元メールアドレス@gmail.com", "アプリパスワード"); //メールを送信する sc.Send(senderMail, recipientMail, subject, body); //senderMail, recipientMail, subject, body //後始末(.NET Framework 4.0以降) sc.Dispose(); }
======================================================================
上記のようにプログラムを書いています。
Gmailに送信しようとしているのですがエラーが出ます。↓
SMTP サーバーにセキュリティで保護された接続が必要であるか、またはクライアントが認証されていません。 サーバーの応答:5.5.1 Authentication Required. Learn more at
何がエラーの原因なのでしょうか
https://teratail.com/questions/136790 と同じ問題ですよね? 前のスレッドでレスがついているのにそれを放置して新たにスレッドを立てるのは、前のスレッドでレスをしてくれた人に失礼では?