Hello,
First of all declare one stringbuilder variable. append whatever you want to send in stringbuilder.make one function sendmail with four parameters like this
public bool Sendmail(string mailFrom, string mailTo, string mailSubject, string mailBody)
{
if (str_MailComponent == "SMTP")
{
return SendMailBySmtp(mailFrom, mailTo, mailSubject, mailBody);
}
else
{
return false;
}
}
then get all the correct details of server, use below function to send the mail, just copy and paste it will work.
public bool SendMailBySmtp(string from, string to, string subject, string body)
{
try
{
MailMessage ObjMailMessage = new MailMessage();
ObjMailMessage.From = new MailAddress(from);
ObjMailMessage.To.Add(new MailAddress(to));
ObjMailMessage.Subject = subject;
ObjMailMessage.Body = body;
ObjMailMessage.IsBodyHtml = true;
ObjMailMessage.Priority = MailPriority.Normal;
SmtpClient ObjSmtpClient = new SmtpClient(str_ServerDetails);
ObjSmtpClient.Port = 25;
if (!String.IsNullOrEmpty(str_UserName))
{
NetworkCredential ObjNC = new NetworkCredential(str_UserName, str_Password);
ObjSmtpClient.Credentials = ObjNC;
}
else
{
ObjSmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
}
ObjSmtpClient.Send(ObjMailMessage);
return true;
}
catch (SmtpException ex)
{
}
catch (FormatException ex)
{
}
catch (ArgumentException ex)
{
}
catch (InvalidOperationException ex)
{
}
catch (System.Security.SecurityException ex)
{
}
catch (ConfigurationErrorsException ex)
{
}
return false;
}
pass the correct parameters to function.