Freemailer - the mashup of SiteExtesnsions and JobHost (WebJobs SDK).
Send emails via WebJob SDK JobHost hosted in this Site Extensions using a MailGun account.
— Submit email contents into the Queue as below and let Freemailer do the rest for you.
Prerequiste
-
MailGun account (if you dont have one and want to send free email, just signup for free)
-
Azure Storage Queue with name "emailqueue," where you will post your email content and details
How to Integrate
1 Add below keys and connection string in the web.config of your website. You may choose to directly add the below keys using Azure portal via configure tab
<connectionstrings>
<add name="AzureWebJobsDashboard" connectionstring="DefaultEndpointsProtocol=https;AccountName=yourStore;AccountKey=yourkey" />
<add name="AzureWebJobsStorage" connectionstring="DefaultEndpointsProtocol=https;AccountName=yourStore;AccountKey=yourKey" />
</connectionstrings>
<appSettings>
<add key="apiKey" value="your-mailgun-key-abcd" />
<add key="domain" value="your-mailgun-domain-sandboxabcd.mailgun.org" />
</appSettings>
2 Create following class which will be used to send email in queue
` public class EmailMessage
{
public string To { get; set; }
public string From { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
}`
3 Use below code to submit email to the queue, basically need to serialize the message using JsonConvert.
CloudQueue queue = queueClient.GetQueueReference("emailqueue");
var message = new EmailMessage();
message.From = "[email protected]";
message.To = "[email protected]";
message.Subject = "Subject";
message.Message = "Message Text";
CloudQueueMessage mess = new CloudQueueMessage(JsonConvert.SerializeObject(message));
queue.AddMessage(mess);
Thats it, as soon as the message is submitted to the Queue, the JobHost will pick it up and send emails using your MailGun account