Cybercrux

Everything is achievable through technology

SMTP Email

public void MailtoCitrus(string subject, string message, string fromEmail, string toEmail)
{

string mailbody;

MailMessage msg = new MailMessage(“XXXXX@XXXX.com”, “” + toEmail + “”);

msg.Subject = subject;

msg.IsBodyHtml = true;

mailbody = message;

msg.Body = string.Format(mailbody);

SmtpClient mailclient = new SmtpClient(“smtp.gmail.com”, 587);

mailclient.EnableSsl = true;

mailclient.Credentials = new NetworkCredential(“XXX.XXX@gmail.com”, “XX”);

mailclient.Send(msg);

}
public bool SendMail( ListDictionary replacements, string templateName, string email, string subject, string savedFileName = null)
{
SmtpClient smtpClient = null;
smtpClient = new SmtpClient
{
Host = “”,
EnableSsl = true,
Credentials = new NetworkCredential(“XXXXXX@XXXXX.com”, “XXXXX”)
};
smtpClient.Port = 587;
var mailDefinition = new MailDefinition
{
Priority = MailPriority.Normal,
BodyFileName = templateName,
Subject = subject,
IsBodyHtml = true
};
MailMessage mailMessage = mailDefinition.CreateMailMessage(email, replacements, new Control());

try
{
smtpClient.Send(mailMessage);
return true;
}
catch (Exception)
{
return false;
}
}

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