我正在尝试通过Gmail向客户发送邮件列表给500个客户,问题是它只发送89然后我收到以下错误:
System.IO.IOException:无法从传输中读取数据 连接:net_io_connectionclosed
当我将500发送到本地接收时,我的代码确实有效。
我已经阅读了很多帖子,客户说她每天限制2000封电子邮件,所以我不知道问题是什么。
任何人都可以对此有所了解。
代码
var emailMessage = new MailMessage();
emailMessage.To.Add(new MailAddress(emailRecipicant,customerName.Trim()));
emailMessage.From = new MailAddress(smtpEmail);
emailMessage.Subject = $"{emailSubject}";
emailMessage.Body = string.Format(body);
emailMessage.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
smtp.UseDefaultCredentials = false;
var credential = new NetworkCredential
{
UserName = smtpUsername,
Password = smtpPassword
};
smtp.Credentials = credential;
smtp.Host = smtpHost;
smtp.Port = Convert.ToInt32(smtpPort);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
//smtp.PickupDirectoryLocation = "C:\\Users\\pht_000\\Desktop\\Customers\\Email\\PickUp\\";
smtp.EnableSsl = false;
smtp.Send(emailMessage);
}
上述void方法通过以下
循环foreach (var recipicant in model.ToList())
{
string emailRecipicant = recipicant.Email;
string emailSubject = recipicant.Subject;
string message1 = recipicant.Message;
string encryptedLink = recipicant.EncryptedEmail;
string customerName = recipicant.Contact;
SendEmail(emailRecipicant, emailSubject, message1, encryptedLink, customerName);
counter++;
}