Kavi Chokshi Kavi Chokshi - 5 months ago 57
ASP.NET (C#) Question

"Request for the permission of type 'System.Net.Mail.SmtpPermission" in .NET when trying to use Amazon SES with shared hosting

We are trying to use Amazon SES to send automated verification emails to users that register.
We have a shared hosting account, and have verified the domain on Amazon SES.

It works locally, but on the server, we keep getting this error:

"Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

We've searched through all similar posts, including this, but are still confused: what are we doing wrong?

Our web.config settings:

<add key="EMAIL_FROM_PREFIX" value="hey UD"></add>
<add key="EMAIL_FROM" value="verify@heyud.com"></add>
<add key="EMAIL_TO" value="admin@heyud.com"></add>
<add key="EMAIL_SUBJECT" value="heyUD user verification"></add>

<add key="SMTP_USERNAME" value="asdf"></add>
<add key="SMTP_PASSWORD" value="asdf"></add>
<add key="SMTP_HOST" value="email-smtp.us-east-1.amazonaws.com"></add>
<add key="SMTP_PORT" value="25"></add>

Here's a screenshot of Elmah: https://www.dropbox.com/s/t2ngk0ddcy0c5q6/Screenshot%202014-01-31%2000.34.06.png


GoDaddy shared hosting tends to be very restrictive (especially when it comes to sending emails though SMTP).

Try using AmazonSimpleEmailServiceClient.SendEmail instead of SMTP.

AmazonSimpleEmailServiceClient client = 
    new AmazonSimpleEmailServiceClient("awsKey", "awsSecret");

SendEmailRequest req = new SendEmailRequest()
    .WithDestination(new Destination() { ToAddresses = new List<string> { "admin@heyud.com" } })
        new Amazon.SimpleEmail.Model.Message(new Content("Sup Bro?"),
        new Body().WithHtml(new Content("<em>Gurl look at ma body</em>, <b>I work out</b>"))));

var resp = client.SendEmail(req);

or forget SES all together and just do this: http://stackoverflow.com/a/5685126/585552 (the from address with have to match the domain of the site you're sending from)