Hi,
I am try to send mail using my application with attachment, disclaimer text (as attachment) and signature. It is working fine.
But when I use a valid credentials in smtpclient, then the From address is set to NetworkCredential objects 1st param (which is an email address).
See my code snippet.
public static string[] TrySendEmail(SecurityContext sc, MessageBase msg)
{
string messageBody = "mail body ....";
var mailMessage = new MailMessage
{
Body = messageBody,
IsBodyHtml = true,
Subject = msg.Subject, From = new MailAddress(msg.SenderMailId) // here is the supplied email address (e.g abc@mymail.com)
};
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(messageBody, null, "text/html");
// Add some mail signature as attachment
// ...
mailMessage.AlternateViews.Add(htmlView);
foreach (var toId in subscriberEmailId)
{
mailMessage.To.Add(new MailAddress(toId));
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = Encoding.UTF8;
}
var client = new SmtpClient();
client.Host = "host_name;
client.EnableSsl = true;
client.Port = portNo;
client.Credentials = new NetworkCredential(smtp.SmtpUserName, smtp.SmtpPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(mailMessage);
}
, which is supplied by user from GUI. Is it possible?