Hi i want to send email using asp.net c# in outlook office id but exception is coming operation time out. i am pasting the code
public void maildetails()
{
dt = dl.maildetails(bl);
string header = "Innovation Gexin";
string body = "Our core team will be reviewing your idea and reach put to you as we progress.Meanwhile, you can also review the progress of the IDEA on the < a href = http://localhost:18993/Pages/Login.aspx> Géxīn portal.";
string body1 = "Alternatively, For more details and queries you can always write to ( gexinblrcoreteam@hp.com )";
string salutation = "Thank you";
string salutation1 = "Regards,CS APJ Care Centre Innovation Team";
string salutation2 = "This is an automatically generated message. Please do not reply to this email.";
StringBuilder sb = new StringBuilder();
sb.AppendLine("<div style=\" width:1100px; padding-left:5px; \" >");
sb.AppendLine("<table width=1100px style=table-layout:fixed; >");
sb.AppendLine("<tr>");
sb.AppendLine("<th colspan=2><span style=\"font-family: 'Times New Roman'; text-align:center; font-size:25px; font-weight:bold\"> </span> </th>");
sb.AppendLine("</tr>");
sb.AppendLine("<tr>");
sb.AppendLine("<td colspan=2> " + header + " </td>");
sb.AppendLine("</tr>");
sb.AppendLine("<tr>");
sb.AppendLine("<th colspan=2><br> </th>");
sb.AppendLine("</tr>");
string to = "xx@outlook.com";
string from = "ccc@outlook.com";
string password = "123";
string subject = "Welcome To Buy & Earn";
body = sb.ToString();
Thread email = new Thread(delegate ()
{
SendEmaill(to, from, password, subject, body);
});
email.IsBackground = true;
email.Start();
}
private void SendEmaill(string to, string from, string password, string subject, string body)
{
try
{
MailMessage mail = new MailMessage();
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["smtpServer"].ToString());
mail.From = new MailAddress(ConfigurationManager.AppSettings["smtpUser"].ToString());
mail.To.Add("xyz@outlook.com");
mail.Subject = "This is a Test Mail";
mail.IsBodyHtml = true;
mail.Body = "This is a test message using Exchange OnLine";
SmtpServer.Port = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]);
SmtpServer.UseDefaultCredentials = false;
//SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
//SmtpServer.Timeout = 20000;
SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser"].ToString(), ConfigurationManager.AppSettings["smtpPass"].ToString());
SmtpServer.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
if (!string.IsNullOrEmpty(bl.fIlename))
{
using (Attachment att = new Attachment(ConfigurationManager.AppSettings["AttachmentPath"].ToString() + "\\" + bl.employeeid + "\\" + bl.fIlename))
{
mail.Attachments.Add(att);
SmtpServer.Send(mail);
}
}
else
{
SmtpServer.Send(mail);
}
}
catch(Exception ex)
{
}