Hello, I have the code which will solve your problem also you will get more knowledge about the sending email in c#. You just need to make use of it, as it is.
Code:
Public string SendMail(StringBuilder content, string Subject, string MailTo, string MailFrom, string SMTPServer, int PortServer)
{
string Back = string.Empty;
MailMessage msg = null;
Encoding Encoding = MyEncoding.GetEncoding("iso-8859-1");
try
{
msg = new MailMessage(MailFrom, MailTo);
msg.Body = Content.ToString();
msg.BodyEncoding = MyEncoding;
msg.IsBodyHtml = false;
msg.Subject = Subject;
SmtpClient smtp = new SmtpClient(SMTPServer, PortServer);
smtp.UseDefaultCredentials = true;
smtp.Send(msg);
Back = "Mail sent to" + MailTo;
}
catch (Exception ex)
{
Back = "Error in Sendmail function - Details:" + Ex.ToString();
}
finally
{
msg = null;
MyEncoding = null;
}
return Back;
}
Bookmarks