Email Proxy on #Azure #Webservice
Here’s a generic way to use a webservice to send email, and it’s been tested with Amazon SES. Proxying email like this saves exposing your own IP address to recipients, to avoid problems with your ISP, or main hosting provider.
Here’s the code;
using System.Net.Mail;
using System.Text;
using System.Threading;
using System.Web.Services;/// <summary>
/// Summary description for EmailProxy
/// </summary>
[WebService(Namespace = “http://emailProxy.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class EmailProxy : WebService {[WebMethod]
public void SendEmail(string smtpHost, string username, string password, int port, string to, string from, string subject, string body) {var client = new SmtpClient
{
Port = port,
Host = smtpHost,
EnableSsl = true,
Timeout = 10000,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(
username,
password)
};
var mm = new MailMessage(from, to, subject, body)
{
BodyEncoding = UTF8Encoding.UTF8,
IsBodyHtml = true,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
};
client.Send(mm);
Thread.Sleep(1000);
}}