Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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")
{
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(smtpUsername, smtpPassword);
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
}
emailClient.Send(mail);
But I am getting below error where i did mistake The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.
Posted
Updated 19-Sep-13 18:48pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900