{"id":28605,"date":"2015-11-04T17:44:04","date_gmt":"2015-11-04T12:14:04","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=28605"},"modified":"2015-11-04T17:45:06","modified_gmt":"2015-11-04T12:15:06","slug":"configuring-nagiospostfix-to-use-aws-ses-as-relay","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/configuring-nagiospostfix-to-use-aws-ses-as-relay\/","title":{"rendered":"Configuring Nagios+Postfix to use AWS SES as relay"},"content":{"rendered":"<h3><b>Introduction<\/b><\/h3>\n<p>Using Postfix to send email notifications to gmail or any such email providers causes relay issue (delay in email delivery) since gmail does not allow multiple emails from non-verified emails. I had to figure out delivering email notifications quickly to avoid any delay in response to the alerts generated by Nagios. AWS has a highly reliable email notification service called SES (Simple Email Service) which can be used to deliver such emails. In this blog I will be configuring postfix to relay the emails alerts from Nagios to use the AWS SES for delivering emails to recipients.This blogs assumes you have a working Nagios (hosts and alerts) configured.<\/p>\n<h3><b>Steps<\/b><\/h3>\n<h3><b>1. Setting up the AWS SES<\/b><\/h3>\n<p>Verify your email which will be used to send emails. You can refer the link http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/verify-email-addresses.html for detailed steps for email verification on SES.<\/p>\n<p>By default SES requires email verification for both sender and receiver email addresses. To avoid verification for the email addresses of recipients a request has to be generated on AWS Support for moving the your SES instance out of the sandbox into production. For detailed steps check the links below:<\/p>\n<p><a href=\"http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/request-production-access.html\">http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/request-production-access.html<\/a><br \/>\n&#8211; SES Email Sending Limits<br \/>\n<i>(<\/i><a href=\"http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/limits.html\"><i>http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/limits.html<\/i><\/a><i>)<\/i><br \/>\n&#8211; Increasing SES Sending Limits<br \/>\n<i>(<\/i><a href=\"http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/increase-sending-limits.html\"><i>http:\/\/docs.aws.amazon.com\/ses\/latest\/DeveloperGuide\/increase-sending-limits.html<\/i><\/a><i>)<\/i><\/p>\n<h3><b>2. Configuring Postfix<\/b><\/h3>\n<p>Configure your Postfix setup to work as relay. On Ubuntu it can be done using following command. <code>dpkg-reconfigure postfix<\/code> On prompting while reconfigure:<\/p>\n<ol>\n<li>Select &#8220;Satellite system&#8221; as your configuration.<\/li>\n<li>Set you SES smtp server as your relay host. To get your exact smtp host, open AWS SES console and click SMTP settings.<\/li>\n<li>Append below lines in \/etc\/postfix\/main.cf<\/li>\n<\/ol>\n<p>[js] smtp_sasl_auth_enable = yes<br \/>\nsmtp_sasl_security_options = noanonymous<br \/>\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd<br \/>\nsmtp_use_tls = yes<br \/>\nsmtp_tls_security_level = encrypt<br \/>\nsmtp_tls_note_starttls_offer = yes<br \/>\nsmtp_tls_CAfile = \/etc\/ssl\/certs\/ca-certificates.crt[\/js]<\/p>\n<p>Enter below details in \/etc\/postfix\/sasl_passwd ( Create if file does not exist ):<\/p>\n<p><code>**Your AWS SES SMTP host **:25 accessid:accesskey<\/code><\/p>\n<p>For the username, password, accessid and accesskey you will have to generate a user name and password for the SES. To generate the username and password follow the below steps:-<\/p>\n<ol>\n<li>Open STMP Settings on your AWS SES console.<\/li>\n<li>Click &#8220;Create My SMTP Credentials&#8221; button and follow the steps.<\/li>\n<\/ol>\n<p>Download the credentials files. The credential files have your accessid and accesskey \u00a0which will be used as username and password.<\/p>\n<ol>\n<li>Execute below commands for further setup:<\/li>\n<\/ol>\n<p>[js]<br \/>\nsudo chown root:root \/etc\/postfix\/sasl_passwd<br \/>\nsudo chmod 0600 \/etc\/postfix\/sasl_passwd<br \/>\nsudo postmap hash:\/etc\/postfix\/sasl_passwd<br \/>\nsudo chown root:root \/etc\/postfix\/sasl_passwd.db<br \/>\nsudo chmod 0600 \/etc\/postfix\/sasl_passwd.db<br \/>\nsudo postconf -e &#8216;smtp_tls_CAfile = \/etc\/ssl\/certs\/ca-certificates.crt&#8217;<br \/>\nservice postfix restart<br \/>\n[\/js]<\/p>\n<p>The configuration is complete. To test your setup try sending a test mail.<br \/>\n<code>echo test | mail -s \"test message\" -a \"From: sender@example\" recepient@example.com<\/code><\/p>\n<address>**If the email fails please check mail log <i>(tailf \/var\/log\/mail.log)<\/i>. If the mail logs shows verification error please check the email ids being used. Both sender and receiver email id should be verified on SES before testing.<\/address>\n<h3><b>3. Configuring Nagios<\/b><\/h3>\n<ul>\n<li>Edit file nagios-installation-dir\/nagios\/etc\/objects\/commands.cfg<\/li>\n<li>add -r sender@example.com at the end of mail commands wherever required.<\/li>\n<\/ul>\n<p>[js]Example:<\/p>\n<p># &#8216;notify-host-by-email&#8217; command definition<\/p>\n<p>define command{<\/p>\n<p>command_name \u00a0\u00a0\u00a0notify-host-by-email<\/p>\n<p>command_line \u00a0\u00a0\u00a0\/usr\/bin\/printf &quot;%b&quot; &quot;***** Nagios *****\\n\\nNotification Type: $NOTIFICATIONTYPE$\\nHost: $HOSTNAME$\\nState: $HOSTSTATE$\\nAddress: $HOSTADDRESS$\\nInfo: $HOSTOUTPUT$\\n\\nDate\/Time: $LONGDATETIME$\\n&quot; | \/usr\/bin\/mail -s &quot;** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **&quot; $CONTACTEMAIL$ -r sender@example.com<\/p>\n<p>}<br \/>\n[\/js]<\/p>\n<p>Restart Nagios :<br \/>\n<code>service nagios restart<\/code><\/p>\n<p>Configuration is complete. Try sending a custom notification via Nagios to test.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Using Postfix to send email notifications to gmail or any such email providers causes relay issue (delay in email delivery) since gmail does not allow multiple emails from non-verified emails. I had to figure out delivering email notifications quickly to avoid any delay in response to the alerts generated by Nagios. AWS has a [&hellip;]<\/p>\n","protected":false},"author":563,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":147},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28605"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/563"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=28605"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28605\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=28605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=28605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=28605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}