C# SMTP Client

static bool SendEmail(String strEmailSubject, String strEmailBody)
{
bool emailSuccess = false;

try
{
SmtpClient smtpClient = new SmtpClient(""); // enter SMTP Server address here
MailMessage email = new MailMessage();

email.From = new MailAddress("a@b.com"); // FROM Address
email.To.Add("a@b.com"); //TO Address

email.IsBodyHtml = true;
//email.BodyFormat = MailFormat.Text;
email.Subject = strEmailSubject;
email.Body = strEmailBody;
smtpClient.Send(email);
Console.WriteLine("Sending Email is successful ");
#endregion Send Email Notification
emailSuccess = true;

}
catch (Exception ex)
{

Console.WriteLine(ex.StackTrace);
return false;
}

return emailSuccess;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s