192

When I searched for configuring sendmail on ubuntu I din't get any clear answer, each of them assume I know what they are talking about,

I just want basic configuration to enable email sending, basically I will use it with google app engine to enable mail sending from dev server.

I already did this:

sudo apt-get install sendmail

then

sudo sendmailconfig

but I don't know what the last one actually did.

Mateng
  • 3,742
  • 5
  • 37
  • 64
UXE
  • 2,374
  • 2
  • 18
  • 17
  • 4
    @ThiefMaster are we not migrating questions to the appropriate SE sites any more? – Michael Dec 03 '14 at 22:58
  • This question is way too old to be migrated (and it already was so when I closed it). – ThiefMaster Dec 03 '14 at 23:01
  • 1
    None of these answers worked for me. I found this online article that works for me: http://www.daveperrett.com/articles/2013/03/19/setting-up-sendmail-with-sendgrid-on-ubuntu/ – Online Sid Jul 22 '16 at 18:42
  • @ThiefMaster define "too old" are you saying sendmail is obsolete? Think again. – PJ Brunet May 25 '19 at 08:58
  • @PJBrunetWhile I do think `sendmail` is obsolete (there are much better alternatives!), my comment FIVE YEARS ago was simply about the fact that we do not migrate questions that old to another SE site. – ThiefMaster May 26 '19 at 20:36
  • That is still broken AF in late 2019 – NVRM Oct 27 '19 at 01:28

3 Answers3

152

When you typed in sudo sendmailconfig, you should have been prompted to configure sendmail.

For reference, the files that are updated during configuration are located at the following (in case you want to update them manually):

/etc/mail/sendmail.conf
/etc/cron.d/sendmail
/etc/mail/sendmail.mc

You can test sendmail to see if it is properly configured and setup by typing the following into the command line:

$ echo "My test email being sent from sendmail" | /usr/sbin/sendmail myemail@domain.example

The following will allow you to add smtp relay to sendmail:

#Change to your mail config directory:
cd /etc/mail

#Make a auth subdirectory
mkdir auth
chmod 700 auth

#Create a file with your auth information to the smtp server
cd auth
touch client-info

#In the file, put the following, matching up to your smtp server:
AuthInfo:your.isp.net "U:root" "I:user" "P:password"

#Generate the Authentication database, make both files readable only by root
makemap hash client-info < client-info
chmod 600 client-info
cd ..

Add the following lines to sendmail.mc, but before the MAILERDEFINITIONS. Make sure you update your smtp server.

define(`SMART_HOST',`your.isp.net')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/auth/client-info.db')dnl

Invoke creation sendmail.cf (alternatively run make -C /etc/mail):

m4 sendmail.mc > sendmail.cf

Restart the sendmail daemon:

service sendmail restart
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Venice
  • 1,858
  • 1
  • 11
  • 10
  • 2
    when trying the last command I get this bash: My test email being sent from sendmail: No such file or directory – UXE Apr 28 '12 at 00:48
  • also what should be edited in those files to enable sending through SMTP server credentials? – UXE Apr 28 '12 at 00:52
  • 1
    Added instructions for adding a smtp relay. – Venice Apr 28 '12 at 01:18
  • 1
    thanks @Venice but when trying m4 sendmail.mc > sendmail.cf I get this error bash: sendmail.cf: Permission denied – UXE Apr 28 '12 at 01:33
  • 1
    Make sure you are doing these commands as sudo. Quicktip: You can create a 'sudo session' by typing 'sudo -s', then enter the sudor password. – Venice Apr 28 '12 at 01:40
  • really I appreciate helping me, and thanks for the sudo session tip.. the last thing I'm facing is this error after typing the last command m4 .... m4 sendmail.mc > sendmail.cf m4:sendmail.mc:101: Warning: excess arguments to builtin `define' ignored m4:sendmail.mc:101: cannot open `/usr/share/sendmail/cf/feature/'authinfo'.m4': No such file or directory – UXE Apr 28 '12 at 01:50
  • Hmm. It looks like you have some extra quotes somewhere in here. It's complaining about the define line, probably the SMART_HOST one. Make sure it follows the pattern of define('KEY', 'VALUE'). Mise well check the other lines you put into the sendmail.mc file as well while your in there. – Venice Apr 28 '12 at 01:57
  • Regarding client-info file, there is possibility that sendmail service is running under smmsp instead root account, so you'll have to update client-info file according to this. – Tiho Jul 11 '12 at 19:55
  • 2
    sorry, when you say `your.isp.net`, do I put `gmail.com` or `smtp.gmail.com` in there? – Houman Jun 27 '13 at 17:08
  • 30
    One thing that isn't clear is what replacements to make in AuthInfo:your.isp.net "U:root" "I:user" "P:password" Specifically, how do you replace U:root and I:user – Tom Haws Aug 29 '13 at 19:06
  • 1
    **BUGS**: sendmail.mc as m4 file honors `x' quoting. – AnFi Feb 06 '14 at 20:55
  • For testing it on localhost, you can use localhost in place of your.isp.net – NeiL Dec 16 '15 at 11:11
  • 14
    In case anyone else is confused, the strings inside the `sendmail.mc` file need to be in the form **BACKTICK** + your text + SINGLE QUOTE. – Thomas Apr 02 '16 at 01:43
  • 2
    This was the only configuration that worked perfectly for me: https://linuxconfig.org/configuring-gmail-as-sendmail-email-relay – Jared Eitnier Jul 19 '16 at 16:11
  • @JaredEitnier Thanks! This works! – Sentimental Jul 28 '16 at 16:12
  • 1
    I don't have an /etc/mail directory... When I do 'which sendmail' I do get /usr/sbin/sendmail so it's there but thats it. Everyone tells me to look in the /etc/mail/ directory but it's so frustrating that it isnt there. – CharliesHeron Jan 03 '17 at 13:12
  • I was concerned that this answer would be outdated but it worked well for me. My SMTP server doesn't require authentication, so I adjusted these steps by using `AuthInfo:your.isp.net "U:root" "I:user"` and omitting the `"P:password"`. The other two I left as-is and it just worked. – Mark Jan 11 '18 at 14:33
  • I know this is old, but thank you for the step-by-step. When we create the "auth" directory and change its permissions to 700 - is that done as root? – emmdee Feb 15 '18 at 23:36
  • @emmdee Yes. Or just `sudo chmod 700 auth` – Andrew Lamarra Feb 16 '18 at 16:29
  • @AndrewLamarra Thanks, was just ensuring that root is supposed to be the owner. That clears it up thanks. – emmdee Feb 17 '18 at 00:46
  • @Ayamei I had that too - it looked like I had sendmail installed, but yum didn't know about it. So I just ran `yum install sendmail`, yum installed it and created `/etc/mail`. – snetch Jan 10 '19 at 15:18
35

I got the top answer working (can't reply yet) after one small edit

This did not work for me:

FEATURE('authinfo','hash /etc/mail/auth/client-info')dnl

The first single quote for each string should be changed to a backtick (`) like this:

FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl

After the change I run:

sudo sendmailconfig

And I'm in business :)

brma
  • 515
  • 5
  • 8
  • 3
    Whether I use your fix or not, when I invoke service sendmail restart, I get fileclass: cannot open 'ATURE(authinfo,': No such file or directory – Tom Haws Aug 29 '13 at 19:01
  • 4
    it's "FEATURE" not "ATURE", check your copy/paste – jyavenard Sep 23 '13 at 00:48
  • you have to paste it at a different location in the sendmail.cf (i put it just above mailer, but i still get no mail) – Toskan Apr 29 '16 at 00:03
14

Combine two answers above, I finally make it work. Just be careful that the first single quote for each string is a backtick (`) in file sendmail.mc.

#Change to your mail config directory:
cd /etc/mail

#Make a auth subdirectory
mkdir auth
chmod 700 auth  #maybe not, because I cannot apply cmd "cd auth" if I do so.

#Create a file with your auth information to the smtp server
cd auth
touch client-info

#In the file, put the following, matching up to your smtp server:
AuthInfo:your.isp.net "U:root" "I:user" "P:password"

#Generate the Authentication database, make both files readable only by root
makemap hash client-info < client-info
chmod 600 client-info
cd ..

#Add the following lines to sendmail.mc. Make sure you update your smtp server
#The first single quote for each string should be changed to a backtick (`) like this:
define(`SMART_HOST',`your.isp.net')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl

#run 
sudo sendmailconfig
flyrain
  • 573
  • 6
  • 11
  • I am still having problem to understand the line AuthInfo... Can you please give one example... ??? – Atul Dravid - White Pvt. Ltd. Feb 20 '14 at 15:47
  • Example, my client-info has only one line, `AuthInfo:smtp.gmail.com "U:username" "P:password"` – flyrain Feb 20 '14 at 18:36
  • Still with all those settings and AuthInfo i fall into SPAM list using smtp.gmail.com with existing account from google.admin AuthInfo: smtp.gmail.com "U:root" "I:name@domain.com" "P:password" also tried AuthInfo: smtp-relay.gmail.com "U:root" "I:name@domain.com" "P:password" – xoxn-- 1'w3k4n Mar 23 '16 at 15:25
  • To clarify: `AuthInfo: smtp.gmail.com "U:yourusername@gmail.com" "P:yourpassword"` – Mendes Nov 29 '16 at 23:39