string smtpServer = "mail.occtbangalore.org";
string smtpAuthentication = (string)Globals.HostSettings["SMTPAuthentication"];
string smtpUsername = (string)Globals.HostSettings["SMTPUsername"];
string smtpPassword = (string)Globals.HostSettings["SMTPPassword"];
MailMessage mail = new MailMessage();
mail.From = new MailAddress("info@myhost.c);
mail.To.Add(txtEmail.Text.Trim());
mail.Subject = "OCCT BANGALORE";
string html = "<img src=\"cid:Logo\" />";
AlternateView av2 = AlternateView.CreateAlternateViewFromString(html,null,text/html");
string logoFile = MapPath(PortalSettings.HomeDirectory + PortalSettings.LogoFile);
if (File.Exists(logoFile))
{
LinkedResource linkedResource = new LinkedResource(logoFile);
linkedResource.ContentId = "Logo";
linkedResource.ContentType.Name = logoFile;
linkedResource.ContentType.MediaType = "image/jpeg";
av2.LinkedResources.Add(linkedResource);
}
mail.AlternateViews.Add(av2);
SmtpClient emailClient = new SmtpClient(smtpServer);
if (smtpAuthentication == "1")
{
NetworkCredential SMTPUserInfo = new NetworkCredential(smtpUsername,smtpPassword);
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
}
emailClient.Send(mail);
当我运行此代码时,我收到此错误:
SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应是:需要 SMTP 身份验证。
我哪里出错了?