I'm sending mail through System.web.mail, my code is as below-
public static void SendEmail(string to, string from, string subject, string body, string SmtpServer, int SmtpPort, string SmtpUser,
string SmtpPassword, bool ssl)
{
try
{
MailMessage myMail = new MailMessage();
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", SmtpServer);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", SmtpPort);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//Use 0 for anonymous
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SmtpUser);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SmtpPassword);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", ssl);
myMail.From = from;
myMail.To = to;
myMail.Subject = subject;
myMail.Body = body;
// System.Web.Mail.SmtpMail.SmtpServer = SmtpServer + ':' + SmtpPort;
System.Web.Mail.SmtpMail.Send(myMail);
}
catch (Exception ex)
{
throw;
}
}
Mail are being sent properly by this code, but when the email is received by the recipient, the from email address is shown as the username of network credential instead of the one I'm passing as From email address. Can anybody suggest me the possible solution?