Mailjet and .net Code Sample

Install

Just add this code in your web.config file for Microsoft .Net 2.0 or higher:

 
  <system.net>
        <mailSettings>
            <smtp  deliveryMethod="Network" from="support@yourdomain.com">
                <network host="in.mailjet.com "
                userName="MAILJET_API_KEY" 
                password="MAILJET_SECRET_KEY"
                port="25" />
            </smtp>
        </mailSettings>
    </system.net>
 

Usage

Here is an example on how to send an e-mail:

 
public static void SendMail(string to, string subject, string body)
        {
            var mailMessage = new System.Net.Mail.MailMessage();
            mailMessage.To.Add(to);
            mailMessage.Subject = subject;
            mailMessage.Body = body; 
            var smtpClient = new SmtpClient();
            smtpClient.Send(mailMessage);
        }
 

If you must use SmtpClient from System.Net.Mail (http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx) This library does not handle TLS, you can use SSL via TCP PORT 465. To handle authentication, the SmtpClient has a Credentials property you can use, either in code, or in the application configuration: http://msdn.microsoft.com/en-us/library/w355a94k.aspx Example:

 
SmtpClient client = new SmtpClient("in.mailjet.com ", "465")
    {
	Credentials = new NetworkCredential("MAILJET_API_KEY", "MAILJET_SECRET_KEY"), 
	EnableSsl = true;
    };
 

Then you can use either two methods Send() from SmtpClient to send emails.