How do I send transactional e-mail to AWS?

4

I use an Ubuntu server in AWS and I can not run the PHP mail () function. Do I need to install something on the server or configure something in the AWS Console?

    
asked by anonymous 29.01.2014 / 21:08

4 answers

7

Limitations related to sending emails from EC2 instances

If you are trying to send emails directly from EC2 instances - that is, without using the Simple Email Service (SES) service - you will probably have the shots blocked after a certain amount of email.

This is because AWS has a strong interest in not allowing users to "tarnish the reputation" of public IPs if any users attempt to send SPAM from EC2 instances, as this would be detrimental to all other clients. / p>

The recommendation is to actually use the SES service, as it brings several advantages briefly listed below.

See more information at EC2 FAQ .

Sending emails through SES (Simple Email Service)

SES facilitates various tasks related to email firing. Using SES, you have:

  • bounces notifications ;
  • notifications of complaints ;
  • rejects notifications ;
  • ease to configure SPF and transparent DKIM (if using Route53)

There are two main ways to use SES: directly through API calls (eg, SendMail), or through SMTP endpoints.

See this documentation page which shows an example of PHP code that triggers emails through SES. This page links to another one that teaches configuring Postfix to trigger emails through SES .

Another way to perform the shots, without the need to configure Postfix, is through the use of PHPMailer. You can specify an SMTP server that PHPMailer will use to trigger emails (in contrast to the mail () function, which will use a local SMTP). So you can configure the SES SMTP endpoint directly in PHPMailer, without the need to install and configure Postfix. See the other code sample answers using PHPMailer.

When you start using SES, you will be in a sandbox and will only be able to fire up to 200 emails per day only for "test" recipients (who should confirm that they accept to receive their emails through a notification of SES itself).

To exit the sandbox and gain production access , you must complete a simple form. In general, the process is fast. When you leave the sandbox, you can initially send 5000 emails per day. If you stay close to that limit, and keep bounce rates and complaints low, the limit will automatically be raised gradually to 1M / day. If you need to fire more than 1M of emails, the process is manual and you should explain your use case to the support.

See more information on the SES page and User Guide (DKIM) .

Sending emails directly through EC2 instances

There are some use cases where it is really necessary to trigger emails from EC2 instances. If you really need this, some steps are needed:

  • Allocate Elastic IPs to instances that will trigger emails.
  • Ask for support to set up reverse DNS for these EIPs.
  • Ask for support to raise the threshold for triggering emails from EC2 instances.
  • You will need to explain your use case to support your request. Note that the SPF and DKIM configuration can not be facilitated by SES / Route53 in this case, and it is your responsibility - it is not mandatory, but the delivery rate can be greatly impaired without the correct configuration and implementation of these two mechanisms. SPAM protection.

    The link to the form can be found at EC2 FAQ previously linked .

        
    30.01.2014 / 06:18
    2

    You must install an SMTP server on the server or use the AWS SES service that you can configure in the AWS Console. I recommend using the PHPMailer component instead of the mail () function as it is easier to configure

        
    29.01.2014 / 21:43
    2

    Here's this video explaining how to proceed (minute 48:30).

    If you do not want to use the SES service on Amazon AWS, you need an SMTP server and the PHPMailer library.

    Using the PHPMailer library, you just need to check the data on your mail server. For example:

    require("phpmailer/class.phpmailer.php");
    
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug = 0; // 1 para aparecer erros e mensagens relacionados com o SMTP, 0 para não aparecerem erros nem mensagens, 2 para mensagens apenas
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "http";
    $mail->Host = "smtpout.secureserver.net"; //neste caso uso a minha conta na Godaddy
    $mail->Port = 80; 
    
    $mail->Username = "<seu nome>";
    $mail->Password = "<sua senha>";
    $mail->From = "<seu email>";
    $mail->FromName = "<seu nome>";
    $mail->AddAddress("<email destinatário>", "<nome destinatário>");
    $mail->AddReplyTo("<seu email>", "<seu nome>");
    
    $mail->WordWrap = 50; // set word wrap to 50 characters
    
    $anexo = "pasta/all.zip"; //caso pretenda enviar anexos
    
    $mail->AddAttachment($anexo, "dados.zip"); // caso queira adicionar um nome diferente ao arquivo de anexo
    $mail->IsHTML(true); // se pretender enviar no formato HTML
    
    $mail->AddEmbeddedImage('img/logo.png', 'logo'); //para enviar como logotipo de assinatura
    $mail->Subject = "<Assunto>";
    $mail->Body    = "A sua mensagem... <a href=\"http://www.seusite.com.br\"><img src=\"cid:logo\" alt=\"Título de seu site\"></a>";
    if($mail->Send())
      echo "Enviado com sucesso";
    else
      echo "Erro ao enviar email";
    
        
    29.01.2014 / 23:06
    1

    Try installing a local mail server, here is a link to the postfix installation / configuration tutorial;

    link

        
    17.02.2014 / 15:07