Difference between revisions of "Enable Outgoing Emails"

From Amahi Wiki
Jump to: navigation, search
 
(13 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
heading =WARNING|
 
heading =WARNING|
 
message = This is recommended only for advanced users, proceed with caution.}}
 
message = This is recommended only for advanced users, proceed with caution.}}
Here's how to enable outgoing emails on your Amahi server.
+
Here's how to enable outgoing emails on your Amahi server  
  
Note: Make sure to use copy-paste to execute those commands. In particular, they contain back-ticks as the starting string delimiter, which can be hard to find on a keyboard!
+
'''NOTE:''' Make sure to use copy-paste to execute those commands. In particular, they contain back-ticks as the starting string delimiter, which can be hard to find on a keyboard!
  
[[Open Terminal as root|As '''root''' user]]:
+
To begin with, [[Open Terminal as root|As '''root''' user]] do the following:
  
{{code|Code=
+
== Option 1 (Internet Service Provider) ==
 +
<pre>
 
SMTP_SERVER=your_isp_smtp_server
 
SMTP_SERVER=your_isp_smtp_server
 
yum -y install sendmail-cf m4
 
yum -y install sendmail-cf m4
Line 17: Line 18:
 
make
 
make
 
chkconfig sendmail on
 
chkconfig sendmail on
service sendmail restart}}
+
service sendmail restart
 
+
</pre>
 
Make sure to replace ''your_isp_smtp_server'' on the first line with the hostname or IP address of your ISP SMTP server.
 
Make sure to replace ''your_isp_smtp_server'' on the first line with the hostname or IP address of your ISP SMTP server.
  
 
If you need to connect to the SMTP server using port 587 (TLS/STARTTLS), you'll need to do this too:
 
If you need to connect to the SMTP server using port 587 (TLS/STARTTLS), you'll need to do this too:
{{code|Code=
+
<pre>
 
cd /etc/mail
 
cd /etc/mail
 
sed -ie "s/\(.*SMART_HOST.*\)/\1\ndefine(\`RELAY_MAILER_ARGS', \`TCP \$h 587')dnl\ndefine(\`ESMTP_MAILER_ARGS', \`TCP \$h 587')dnl/" sendmail.mc
 
sed -ie "s/\(.*SMART_HOST.*\)/\1\ndefine(\`RELAY_MAILER_ARGS', \`TCP \$h 587')dnl\ndefine(\`ESMTP_MAILER_ARGS', \`TCP \$h 587')dnl/" sendmail.mc
 
make
 
make
 
service sendmail restart
 
service sendmail restart
}}
+
</pre>
 
If you want to use another port than 587, change that number in the above command (it's there twice), before executing it. If you already executed it, edit the sendmail.mc file, and search for 587 - it should appear there twice - change both.
 
If you want to use another port than 587, change that number in the above command (it's there twice), before executing it. If you already executed it, edit the sendmail.mc file, and search for 587 - it should appear there twice - change both.
  
Line 43: Line 44:
 
  service sendmail restart
 
  service sendmail restart
 
</div>-->
 
</div>-->
{{code|Code=
+
<pre>
 
SMTP_SERVER=your_isp_smtp_server
 
SMTP_SERVER=your_isp_smtp_server
 
USERNAME=your_smtp_username
 
USERNAME=your_smtp_username
Line 54: Line 55:
 
make
 
make
 
service sendmail restart
 
service sendmail restart
}}
+
</pre>
 +
Set sendmail to start on boot
 +
<pre>
 +
systemctl enable sendmail
 +
</pre>
 +
 
 +
== Option 2 (Google Gmail) ==
 +
<pre>
 +
su -
 +
yum -y install sendmail-cf mailx
 +
cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc.orig
 +
vi /etc/mail/sendmail.mc
 +
</pre>
 +
Near the very bottom before MAILER insert the following lines. Sendmail is picky about the quotation marks: when I first pasted them, they were wrong and gave me a syntax error. This section is a combination of the two sources above which fixes the error in /var/log/maillog “no route to host” which apparently has nothing to do with DNS resolution.
 +
<pre>
 +
define(`SMART_HOST',`smtp.gmail.com')dnl
 +
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
 +
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
 +
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
 +
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
 +
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')
 +
</pre>
 +
Then save. Back in the terminal:
 +
<pre>
 +
mkdir /etc/mail/auth
 +
vi /etc/mail/auth/client-info
 +
AuthInfo:smtp.gmail.com "U:root" "I:<YOUR GMAIL USERNAME HERE>@gmail.com" "P:<YOU GMAIL PASSWORD HERE>"
 +
</pre>
 +
Of course, fill out your real login info, save, and exit. The next section skips the part about the openssl certificates: I ran it, but it didn’t seen to be necessary on Fedora.
 +
<pre>
 +
cd /etc/mail/auth
 +
makemap hash client-info.db < client-info
 +
chmod 700 /etc/mail/auth
 +
chmod 600 /etc/mail/auth/*
 +
cd /etc/mail
 +
make
 +
systemctl restart sendmail
 +
</pre>
 +
Set sendmail to start on boot
 +
<pre>
 +
systemctl enable sendmail
 +
</pre>
 +
== Test ==
 +
Finally, send a test email.
 +
<pre>
 +
echo 'this is a test'| mail -s test_email user@example.com
 +
</pre>
 +
If it fails, read /var/log/maillog and /var/log/messages.
 +
 
 +
Ref:  [http://www.techvilleottawa.org/sendmail-smtp-gmail-relay-on-fedora-centos-redhat Sendmail SMTP Gmail Relay on Fedora-Centos-Redhat]
 +
 
 +
== Troubleshooting ==
 +
* If you get the message " warning: SASL authentication failure: No worthy mechs found", install this package.
 +
yum install cyrus-sasl{,-plain}
 +
 
 +
:Restart Sendmail
 +
systemctl restart sendmail

Latest revision as of 16:16, 7 September 2015

Warning.png WARNING
This is recommended only for advanced users, proceed with caution.


Here's how to enable outgoing emails on your Amahi server

NOTE: Make sure to use copy-paste to execute those commands. In particular, they contain back-ticks as the starting string delimiter, which can be hard to find on a keyboard!

To begin with, As root user do the following:

Option 1 (Internet Service Provider)

SMTP_SERVER=your_isp_smtp_server
yum -y install sendmail-cf m4
cd /etc/mail
sed -ie "s/.*SMART_HOST.*/define(\`SMART_HOST', \`$SMTP_SERVER')dnl/" sendmail.mc
make
chkconfig sendmail on
service sendmail restart

Make sure to replace your_isp_smtp_server on the first line with the hostname or IP address of your ISP SMTP server.

If you need to connect to the SMTP server using port 587 (TLS/STARTTLS), you'll need to do this too:

cd /etc/mail
sed -ie "s/\(.*SMART_HOST.*\)/\1\ndefine(\`RELAY_MAILER_ARGS', \`TCP \$h 587')dnl\ndefine(\`ESMTP_MAILER_ARGS', \`TCP \$h 587')dnl/" sendmail.mc
make
service sendmail restart

If you want to use another port than 587, change that number in the above command (it's there twice), before executing it. If you already executed it, edit the sendmail.mc file, and search for 587 - it should appear there twice - change both.

If you need to provide a username and password to use the SMTP server, you'll need to do this too:

SMTP_SERVER=your_isp_smtp_server
USERNAME=your_smtp_username
PASSWORD=your_smtp_password
cd /etc/mail
chmod 600 access
echo "AuthInfo:$SMTP_SERVER \"U:$USERNAME\" \"P:$PASSWORD\" \"M:PLAIN\"" >> access
makemap -r hash access.db < access
sed -ie "s/.*confAUTH_MECHANISMS.*/define(\`confAUTH_MECHANISMS', \`EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl\nFEATURE(\`authinfo',\`hash \/etc\/mail\/access')dnl/" sendmail.mc
make
service sendmail restart

Set sendmail to start on boot

systemctl enable sendmail

Option 2 (Google Gmail)

su -
yum -y install sendmail-cf mailx
cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc.orig
vi /etc/mail/sendmail.mc

Near the very bottom before MAILER insert the following lines. Sendmail is picky about the quotation marks: when I first pasted them, they were wrong and gave me a syntax error. This section is a combination of the two sources above which fixes the error in /var/log/maillog “no route to host” which apparently has nothing to do with DNS resolution.

define(`SMART_HOST',`smtp.gmail.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')

Then save. Back in the terminal:

mkdir /etc/mail/auth
vi /etc/mail/auth/client-info
AuthInfo:smtp.gmail.com "U:root" "I:<YOUR GMAIL USERNAME HERE>@gmail.com" "P:<YOU GMAIL PASSWORD HERE>"

Of course, fill out your real login info, save, and exit. The next section skips the part about the openssl certificates: I ran it, but it didn’t seen to be necessary on Fedora.

cd /etc/mail/auth
makemap hash client-info.db < client-info
chmod 700 /etc/mail/auth
chmod 600 /etc/mail/auth/*
cd /etc/mail
make
systemctl restart sendmail

Set sendmail to start on boot

systemctl enable sendmail

Test

Finally, send a test email.

echo 'this is a test'| mail -s test_email user@example.com

If it fails, read /var/log/maillog and /var/log/messages.

Ref: Sendmail SMTP Gmail Relay on Fedora-Centos-Redhat

Troubleshooting

  • If you get the message " warning: SASL authentication failure: No worthy mechs found", install this package.
yum install cyrus-sasl{,-plain}
Restart Sendmail
systemctl restart sendmail