我用来发送电子邮件的代码有效,但突然不再有效。它给我错误“邮箱不可用。服务器响应为:在端口587上提交邮件需要SMTP AUTH”。我正在浏览一个客户列表,我想发送电子邮件,这些电子邮件中嵌入了一张图片
当我试图查找问题的可能原因时,我将访问修饰符从protected更改为private-多数民众赞成在我停下来并再次运行该问题时出现错误提示“ Invalid helo name”时,返回说“在端口587上提交邮件需要SMTP AUTH”。
private void sendHtmlEmail(string from_Email, string to_Email, string body, string from_Name, string Subject, string SMTP_IP, Int32 SMTP_Server_Port, string Email_ImageFilePath)
{
using (MailMessage mail = new MailMessage())
{
mail.IsBodyHtml = true;
using (AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html"))
{
using (LinkedResource theEmailImage = new LinkedResource(Email_ImageFilePath))
{
theEmailImage.ContentId = "myImageID";
//Add the Image to the Alternate view
htmlView.LinkedResources.Add(theEmailImage);
//Add view to the Email Message
mail.AlternateViews.Add(htmlView);
//set the "from email" address and specify a friendly 'from' name
mail.From = new MailAddress("myemail@fff.co.za");
//set the "to" email address
mail.To.Add(to_Email);
//set the Email subject
mail.Subject = Subject;
//set the SMTP info
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("myemail@fff.co.za", "password");
SmtpClient smtp = new SmtpClient("mail.fff.co.za", 587);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.Send(mail);
}
}
}
}