1

I'm configuring Amazon Simple Email Service, I get to the point when I try to send an email and I get the error message:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required

So I'd like to use a self-signed certificate using IIS 8, but so far I've implemented it and I'm still getting the same error.

  • I'm using .net web.config to set the credentials, hostname, and port.
<mailSettings>
      <smtp from="emal@email.com" deliveryMethod="Network" >
        <network
          host="my-amazon-host.com"
          port="25"
          defaultCredentials="false"
          enableSsl="true"
          userName="my-user-name"
          password="my-password" />
      </smtp>
</mailSettings>
  • is there any way to use the self-signed certificate (created by the IIS) and amazon-ses service?
  • how to set up that certificate?

thanks in advance!

pedrommuller
  • 279
  • 5
  • 13

1 Answers1

0

I read this:

The .NET email TLS libraries only support STARTTLS which SES does not support today. We support what is called "TLS Wrapper" or SMTPS authentication. I can understand how this would be frustrating, but you can use OpenSSL as a workaround and tunnel through that software running on your computer to use .NET to program against our SMTP endpoint.

so I decided to make a custom smtp implementation using amazon SDK:

        var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
        var toAddresses = email.To.Select(mailAddress => mailAddress.Address).ToList();
        var destination = new Destination {ToAddresses = toAddresses};
        var subject = new Content(email.Subject);
        var textBody = new Content(email.Body);
        var body = new Body(textBody);
        var message = new Message(subject,body);
        var request = new SendEmailRequest(smtpSection.From, destination, message);
        Amazon.RegionEndpoint region = Amazon.RegionEndpoint.USEast1;
        var client = new AmazonSimpleEmailServiceClient(region);

        try
        {
            client.SendEmail(request);

        }
        catch (Exception ex)
        {
            //TODO: logger.
            throw;
        }
        finally 
        {
            email.Dispose();
            client.Dispose();
        }

and also you need to setup a policy to you user in Iam with the following permissions:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "---------",
      "Effect": "Allow",
      "Action": [
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

and remember to add the amazon settings in the app or web config:

  <add key="AWSAccessKey" value="-----------------"/>
  <add key="AWSSecretKey" value="-----------------"/>

I hope that helps anybody else. thanks!

pedrommuller
  • 279
  • 5
  • 13