Sending email from Azure
Solution 1:
I know this is an old post but I've just signed up for Azure and I get 25,000 emails a month for free via SendGrid. These instructions are excellent, I was up and running in minutes:
How to Send Email Using SendGrid with Azure
Azure customers can unlock 25,000 free emails each month.
Solution 2:
Sending from a third party SMTP isn't restricted by or specific to Azure. Using System.Net.Mail, create your message, configure your SMTP client, send the email:
// create the message
var msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add(strTo);
msg.Subject = strSubject;
msg.IsBodyHtml = true;
msg.Body = strMessage;
// configure the smtp server
var smtp = new SmtpClient("YourSMTPServer")
{
Credentials = new System.Net.NetworkCredential("YourSMTPServerUserName", "YourSMTPServerPassword")
};
// send the message
smtp.Send(msg);
UPDATE: I added a post on Medium about how to do this with an Azure Function - https://medium.com/@viperguynaz/building-a-serverless-contact-form-f8f0bff46ba9
Solution 3:
I would never recommend SendGrid. I took up their free account offer and never managed to send a single email - all got blocked - I spent days trying to resolve it. When I enquired why they got blocked, they told me that free accounts share an ip address and if any account abuses that ip by sending spam - then everyone on the shared ip address gets blocked - totally useless. Also if you use them - do not store your email key in a git public repository as anyone can read the key from there (using a crawler) and use your chargeable account to send bulk emails.
A free email service which I've been using reliably with an Azure website is to use my Gmail (Google mail) account. That account has an option for using it with applications - once you enable that, then email can be sent from your azure website. Pasting in sample send code as the port to use (587) is not obvious.
public static void SendMail(MailMessage Message)
{
SmtpClient client = new SmtpClient();
client.Host = EnvironmentSecret.Instance.SmtpHost; // smtp.googlemail.com
client.Port = 587;
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Credentials = new NetworkCredential(
EnvironmentSecret.Instance.NetworkCredentialUserName,
EnvironmentSecret.Instance.NetworkCredentialPassword);
client.Send(Message);
}
Solution 4:
A nice way to achieve this "if you have an office 365 account" is to use Office 365 outlook connector integrated with Azure Logic App,
Hope this helps someone!
Solution 5:
If you're looking for some ESP alternatives, you should have a look at Mailjet for Microsoft Azure too! As a global email service and infrastructure provider, they enable you to send, deliver and track transactional and marketing emails via their APIs, SMTP Relay or UI all from one single platform, thought both for developers and emails owners.
Disclaimer: I’m working at Mailjet as a Developer Evangelist.