Home > Uncategorized > Email Proxy on #Azure #Webservice

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/&#8221;)]
[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 {

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(
var mm = new MailMessage(from, to, subject, body)
BodyEncoding = UTF8Encoding.UTF8,
IsBodyHtml = true,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

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 )

Connecting to %s

%d bloggers like this: