In this blog I am explaining how to send mail on any domain using exchange server. You can implement exchange server following these step.
Step 1 - Create a web application.
Step 2 - Add "Microsoft.Exchange" library reference in your application.
PM>Install-Package Microsoft.Exchange.WebServices
See this image and add "Microsoft.Exchange" library in your application.
Thereafter create a method to create mailing concept using exchange server.
-
- public class SendmailByOutLook
- {
- string MailUser = WebConfigurationManager.AppSettings["MailUser"].ToString();
- string MailPass = WebConfigurationManager.AppSettings["mailPass"].ToString();
- string MailTo = WebConfigurationManager.AppSettings["MailTo"].ToString();
- public bool SendMail(RequestInsights info)
- {
- try
- {
- ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
- service.Credentials = new NetworkCredential(MailUser,MailPass);
- service.AutodiscoverUrl(MailUser);
- EmailMessage emailMessage = new EmailMessage(service);
- emailMessage.Subject =info.Subject;
- emailMessage.Body = new MessageBody("<table><tr><td>Hi Admin,</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Name</td><td>:</td><td>" +info.Name+ "</td></tr><tr><td></td><td></td><td></td></tr><tr><td>Email</td><td>:</td><td>" + info.EmailId + "</td></tr><tr><td></td><td></td><td></td></tr><tr><td>Details</td><td>:</td><td>" + info.Details+ "</td></tr><tr><td></td><td></td><td></td></tr><tr><td>Date</td><td>:</td><td>" + DateTime.Now.ToString() + "</td></tr></table>");
- emailMessage.ToRecipients.Add(MailTo);
- emailMessage.SendAndSaveCopy();
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
-
- }
- }
In this example you can customize these thing according your requirement.
- string MailUser = WebConfigurationManager.AppSettings["MailUser"].ToString();
- string MailPass = WebConfigurationManager.AppSettings["mailPass"].ToString();
- string MailTo = WebConfigurationManager.AppSettings["MailTo"].ToString();
And also message body.
- emailMessage.Body = new MessageBody("<table><tr><td>Hi Admin,</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Name</td><td>:</td><td>" +info.Name+ "</td></tr><tr><td></td><td></td><td></td></tr><tr><td>Email</td><td>:</td><td>" + info.EmailId + "</td></tr><tr><td></td><td></td><td></td></tr><tr><td>Details</td><td>:</td><td>" + info.Details+ "</td></tr><tr><td></td><td></td><td></td></tr><tr><td>Date</td><td>:</td><td>" + DateTime.Now.ToString() + "</td></tr></table>");
Thanks...