Skip to content

Instantly share code, notes, and snippets.

@adamstac
Last active January 5, 2024 00:01
Show Gist options
  • Star 89 You must be signed in to star a gist
  • Fork 39 You must be signed in to fork a gist
  • Save adamstac/7462202 to your computer and use it in GitHub Desktop.
Save adamstac/7462202 to your computer and use it in GitHub Desktop.
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
@ladsoftware
Copy link

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

@m-ric
Copy link

m-ric commented Sep 22, 2017

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

@stnc
Copy link

stnc commented Oct 20, 2017

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

@yogesh-15git
Copy link

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

@sensonicm
Copy link

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
Copy link

yfarooq 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
Copy link

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
Copy link

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

@agnesyangwei
Copy link

Works for me. Greatly appreciated.

@youssman
Copy link

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

More details here

@crmpicco
Copy link

Really useful, thanks.

@sensonicm
Copy link

@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
Copy link

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
Copy link

gianpaj commented Mar 21, 2018

@elewinso, try to run:

sudo apt-get update

@TheRatG
Copy link

TheRatG 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
Copy link

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

@Keyzo-Gakiya
Copy link

Worked fine for me (Ubuntu 18.04), Thanks!

@nilliu
Copy link

nilliu 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
Copy link

yfarooq 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
Copy link

inneroot 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.

@bitridge
Copy link

bitridge 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

@NSBSD-InfoTech
Copy link

Its working for me, the problem is the email address showing up on my email is it@localhost, how can I make it to show the hostname of the server and not localhost?

@sarraHa
Copy link

sarraHa commented Dec 3, 2019

Worked fine for me (Ubuntu 18.04), Thanks!

I used this tutorial for ubuntu 18.04
https://www.youtube.com/watch?v=_nwJ63UhJTM

@jet2018
Copy link

jet2018 commented Feb 24, 2020

after doing your steps, i get this
[Mon Feb 24 09:50:24.782752 2020] [mpm_prefork:notice] [pid 11060] AH00169: caught SIGTERM, shutting down
[Mon Feb 24 09:52:08.852440 2020] [mpm_prefork:notice] [pid 1128] AH00163: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Mon Feb 24 09:52:09.024401 2020] [core:notice] [pid 1128] AH00094: Command line: '/usr/sbin/apache2'

what do i do?

@iotstudent
Copy link

pls how do i locate the sendmail.ini file in ubuntu 18

@bhaijiyunus
Copy link

bhaijiyunus commented Apr 16, 2020

HI,
I run the below commands on my Ubuntu 18.04 to configure the sendemail/sendmail, I am getting email success message but never received an email. Help will appreciate. Thanks.
Apr 16 15:45:01 ubuntu sendemail[29360]: Email was sent successfully!
systemctl stop postfix
sudo apt remove postfix
sudo apt purge postfix
sudo apt-get install mailutils
sudo apt-get install sendmail sendemai

@charity1475
Copy link

How to make sendmail work in a LAN? or between two computers connected via eht0

@bitridge
Copy link

How to make sendmail work in a LAN? or between two computers connected via eht0

Good question, I'm following

@Dissorder
Copy link

Hi @bhaijiyunus I'm getting the same issue. Were you able to solve it?

@thesimonshields
Copy link

Not working for me either

wondering if I could get the code and compile it

i get errors around missing packages javascript-common & sometimes java-common

sudo apt -f install sendmail
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-5.4.0-74-generic linux-headers-5.4.0-77-generic linux-hwe-5.4-headers-5.4.0-56 linux-hwe-5.4-headers-5.4.0-58
linux-hwe-5.4-headers-5.4.0-74 linux-hwe-5.4-headers-5.4.0-77 linux-image-5.4.0-74-generic linux-image-5.4.0-77-generic
linux-modules-5.4.0-74-generic linux-modules-5.4.0-77-generic linux-modules-extra-5.4.0-74-generic linux-modules-extra-5.4.0-77-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
liblockfile-bin liblockfile1 lockfile-progs procmail sendmail-base sendmail-bin sendmail-cf sensible-mda
Suggested packages:
sendmail-doc rmail logcheck resolvconf sasl2-bin
The following NEW packages will be installed:
liblockfile-bin liblockfile1 lockfile-progs procmail sendmail sendmail-base sendmail-bin sendmail-cf sensible-mda
0 to upgrade, 9 to newly install, 0 to remove and 292 not to upgrade.
Need to get 0 B/899 kB of archives.
After this operation, 4,449 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package liblockfile-bin.
dpkg: warning: files list file for package 'javascript-common' missing; assuming package has no files currently installed
dpkg: unrecoverable fatal error, aborting:
files list file for package 'libv4l-0:i386' contains empty filename
E: Sub-process /usr/bin/dpkg returned an error code (2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment