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

StackOverflow https://stackoverflow.com/questions/21465461

  •  05-10-2022
  •  | 
  •  

Question

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=4.0.0.0, 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:

<appSettings>
    ...
    <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>
  </appSettings>

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

Was it helpful?

Solution

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" } })
    .WithSource("verify@heyud.com")
    .WithReturnPath("verify@heyud.com")
    .WithMessage(
        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: https://stackoverflow.com/a/5685126/585552 (the from address with have to match the domain of the site you're sending from)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top