大家好:
gmail(587 port)是否能大量寄信..因為我用寄信視窗程式(winform)C#迴圈寄,用gmail當smtp server,程式會卡死,所以又修正非同步(asnyc await),雖然會有點慢,但至少程式不會卡死
但是執行一陣子程式會回覆以下資訊造成中斷,想請問有甚麼方法改善
ServiceNotAvailable 421
SMTP 服務目前無法使用;伺服器正在關閉傳送通道。
用自家公司信箱 25 port算順利 Q_Q
好像587 port用迴圈gmail跟yahoo真的不行大量寄Orz
private async void button1_Click(object sender, EventArgs e)
{
try
{
SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
login = new NetworkCredential("sample@gmail.com", "srcbn");
SmtpServer.Credentials = login;
SmtpServer.EnableSsl = true;
SmtpServer.Port = 587;
Mymail = new MailMessage();
Mymail.SubjectEncoding = System.Text.Encoding.UTF8;
string senderNameb64Enc = Convert.ToBase64String(Encoding.UTF8.GetBytes("aaavvvv"));
Mymail.From = new MailAddress("sample@gmail.com", $"=?UTF-8?B?{senderNameb64Enc}?=", System.Text.Encoding.GetEncoding("UTF-8"));
Mymail.IsBodyHtml = true; //是否用html格式
Mymail.BodyEncoding = System.Text.Encoding.UTF8;
string[] formdata = { "sample@yahoo.com" };
for (int i = 0; i < 500; i++)
{
Mymail.Subject = "aaaqq"+i.ToString();
foreach (string email in formdata)
{
Mymail.To.Add(email);
await SmtpServer.SendMailAsync(Mymail);
// SmtpServer.Send(Mymail);
}
}
MessageBox.Show("OK");
}
catch (SmtpException ex)
{
MessageBox.Show(ex.StatusCode.ToString());
}
}