Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install and configure Sendmail on Ubuntu

Install and configure Sendmail on Ubuntu

This should help you get Sendmail installed with basic configuration on Ubuntu.

  1. If sendmail isn't installed, install it: sudo apt-get install sendmail
  2. Configure /etc/hosts file: nano /etc/hosts
  3. Make sure the line looks like this: 127.0.0.1 localhost yourhostname
  4. Run Sendmail's config and answer 'Y' to everything: sudo sendmailconfig
  5. Restart apache sudo service apache2 restart
@nelsons18

This comment has been minimized.

Copy link

commented Jan 14, 2016

This should help you get Sendmail installed with basic configuration on Ubuntu.

@ronalddas

This comment has been minimized.

Copy link

commented Sep 11, 2016

To find 'yourhostname', just type hostname in the terminal

@tarrsalah

This comment has been minimized.

Copy link

commented Oct 27, 2016

I'm getting dsn=5.0.0, stat=Service unavailable in my /vatr/log/mail.log, did the exact same steps.

@pritam1605

This comment has been minimized.

Copy link

commented Jan 11, 2017

I am getting dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.

@ericovva

This comment has been minimized.

Copy link

commented Apr 3, 2017

thanks!

@statmonkey

This comment has been minimized.

Copy link

commented Jul 22, 2017

grrr! embarrassed I needed this but I went arch for a few years and had forgotten my debian setup. Thanks for this. For local mail just add mutt and mailutils and your done.

@ladsoftware

This comment has been minimized.

Copy link

commented Sep 15, 2017

not working for me.
mail() is returns true, but i'm not getting email at hotmail or gmail.

@m-ric

This comment has been minimized.

Copy link

commented Sep 22, 2017

restart apache2, really? Why would you need to do that?

@stnc

This comment has been minimized.

Copy link

commented Oct 20, 2017

if lemp server is
sudo service nginx restart
service php7.0-fpm restart

@yogesh-15git

This comment has been minimized.

Copy link

commented Oct 24, 2017

mail() is returning FALSE.. Not working for me (Ubuntu 16.04)

@sensonicm

This comment has been minimized.

Copy link

commented Nov 7, 2017

I like such blabbering as @m-ric, just to say something ...

on a clean server, do not forget to check whether you need a php-mail:
$ sudo apt-get install php-mail

To be sure, restart the server and execute the configuration with the command:
$ sudo /usr/sbin/sendmailconfig

Checking from the console (with the -v switch being traced):
$ echo "test message" | sendmail -v your@mail.com

You can also configure the settings in the php.ini: "...sendmail_path = /usr/sbin/sendmail -t -i"

I for example set up separately for each virtual host in my_vhost.conf:
<IfModule php[ver]_module>
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f admin@example.com"

...many services, Google for example, require that a PTR record is specified, you can see this in the trace when the test is sent from the console with the key -v

@yfarooq

This comment has been minimized.

Copy link

commented Nov 7, 2017

Hi Everyone,

I followed the instruction and for some reason, i can get this working. here is my log

sender@xyz:~$ echo "test message" | sendmail -v reciver@me.com
reciver@me.com... Connecting to [127.0.0.1] via relay...
220 xyz.com ESMTP Sendmail 8.15.2/8.15.2/Debian-3; Wed, 8 Nov 2017 01:21:43 +0800; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]

EHLO xyz.com
250-xyz.com Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
VERB
250 2.0.0 Verbose mode
MAIL From:sender@xyz.com SIZE=13 AUTH=sender@xyz.com
250 2.1.0 sender@xyz.com... Sender ok
RCPT To:reciver@me
DATA
250 2.1.5 reciver@me... Recipient ok
354 Enter mail, end with "." on a line by itself
.

@sensonicm

This comment has been minimized.

Copy link

commented Dec 28, 2017

Hi @yfarooq !
Congratulations on the coming New Year!
We would have made the world better if we told how we solved our problems)))
Or not yet solved?
The problem in determining the e-mail address in the listing about this is written, the address should be of the form: some@some.zone(add [.zone] to normal resolve mail address).

@SavaNETgit

This comment has been minimized.

Copy link

commented Jan 7, 2018

Hi All,
sensonicm, How to do it ?
(add [.zone] to normal resolve mail address).

@agnesyangwei

This comment has been minimized.

Copy link

commented Feb 1, 2018

Works for me. Greatly appreciated.

@youssman

This comment has been minimized.

Copy link

commented Feb 12, 2018

Not working on ubuntu 16.04. It is hanging while trying to generate ssl certificates.

More details here

@crmpicco

This comment has been minimized.

Copy link

commented Feb 19, 2018

Really useful, thanks.

@sensonicm

This comment has been minimized.

Copy link

commented Feb 21, 2018

@SavaNETgit Hi all!
In the example above there was an address "reciever@me.com", you need to specify an address with a specific zone, e.g. "sensonicm@gmail.com" The example did not work because the service could not determine the address.
@youssman
Everything works, look in the internet for information - you need to create a certificate before installation. It hangs during installation on the generation of the certificate. Spend the time, look, I have no time. If you do not find write, I'll find)

@elewinso

This comment has been minimized.

Copy link

commented Mar 13, 2018

getting this error, help will be greatly appreciated.

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package sendmail is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'sendmail' has no installation candidate
@gianpaj

This comment has been minimized.

Copy link

commented Mar 21, 2018

@elewinso, try to run:

sudo apt-get update
@TheRatG

This comment has been minimized.

Copy link

commented Apr 10, 2018

I have to run

cd /etc/mail/tls
sudo openssl dsaparam -out sendmail-common.prm 2048
sudo chown root:smmsp sendmail-common.prm
sudo chmod 0640 sendmail-common.prm
sudo dpkg --configure -a
@eugenelee0420

This comment has been minimized.

Copy link

commented May 16, 2018

The installation will hang on Ubuntu 16.04, the solution is to run these commands:

sudo openssl dsaparam -out sendmail-common.prm 2048
sudo chown root:smmsp sendmail-common.prm
sudo chmod 0640 sendmail-common.prm
sudo dpkg --configure -a

Reference: https://askubuntu.com/questions/937666/ubuntu-16-04-command-line-sendmail-installation-hanged

@keyzotech

This comment has been minimized.

Copy link

commented Jul 11, 2018

Worked fine for me (Ubuntu 18.04), Thanks!

@nilliu

This comment has been minimized.

Copy link

commented Sep 17, 2018

really helpful.
I did only from step 1 to 4,
then it's works like a charm!

my use case is sending internal system(ubuntu 18.04) email notification to users in corporate colleague,
and no need of posfix, just need follow step 1 to 4, fast and neat!

thank you.

@yfarooq

This comment has been minimized.

Copy link

commented Oct 3, 2018

Hi @yfarooq !
Congratulations on the coming New Year!
We would have made the world better if we told how we solved our problems)))
Or not yet solved?
The problem in determining the e-mail address in the listing about this is written, the address should be of the form: some@some.zone(add [.zone] to normal resolve mail address).

I still can't get this to work.

Error: /etc/mail/submit.cf: line 6: invalid argument to V line: "ERSIONID(Id: startt"
/etc/mail/submit.cf: line 7: invalid argument to V line: "ERSIONID(Id: autoco"

I tired to comment both line 6 and 7 with # and still can't receive email

@inneroot

This comment has been minimized.

Copy link

commented Dec 4, 2018

'yourhostname' should be long,
that mean, it should have dot com or similar, or you will get error in log:

unable to qualify my own domain name (hostname) - using short name.

@hasanzaheer

This comment has been minimized.

Copy link

commented Jul 9, 2019

For this I think you'll also have to allow gmail on less secure app https://support.google.com/accounts/answer/6010255?hl=en

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.