Simple mail send on Ubuntu

1

1

I have been struggling with mail function in Ubuntu. My goal is to send a test email from a terminal with a command:

echo "msg" | mail -s subject sample@domain.com.

I have tried to install sendmail, but figured out that it could send if I rely on rely server(google smtp). I have tried to install exim4, but in logs provides this data:

2015-11-10 19:09:03 1ZwCPm-00015C-TP <= root@localhost U=root P=local S=788  
2015-11-10 19:09:03 1ZwCPm-00015C-TP ** localhost@localdomain <root@localhost>: Unrouteable address  
2015-11-10 19:09:03 1ZwCPm-00015C-TP => /var/mail/mail (root@localhost) <root@localhost> R=mail4root T=address_file 

2015-11-10 19:09:03 1ZwCPn-00015H-4o <= <> R=1ZwCPm-00015C-TP U=Debian-exim P=local S=1607 

2015-11-10 19:09:03 1ZwCPm-00015C-TP Completed

I have no experience before configuring mail servers. Is it possible to do such action without having FQDN and domain name? Where do I start my investigation on such topic?

qop

Posted 2015-11-10T17:19:11.897

Reputation: 11

Answers

1

Install the postfix package and edit your configuration (usually at /etc/postfix/main.cf) to be:

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd

Now, create the /etc/postfix/sasl directory and create a file called passwd inside with this content:

[smtp.gmail.com]:587    your_username@gmail.com:PASSWORD

Finally, use this command:

postmap /etc/postfix/sasl/passwd

Now, if you use the first syntax (which was correct), you should get your e-mail sent:

echo "msg" | mail -s subject sample@domain.com.

nKn

Posted 2015-11-10T17:19:11.897

Reputation: 4 960

Is this possible if I don't want to rely on relayhost? – qop – 2015-11-11T19:30:22.467

relayhost is the host through which you will send your messages. If you don't want to use a Gmail account, you'll need to specify a different provider and configure your client so it will allow you sending e-mails. – nKn – 2015-11-11T19:36:06.353

I cannot create my own host? – qop – 2015-11-11T19:36:45.320

Sure, for that you should configure your own e-mail server. For allowing it to work correctly, you should use a real DNS host so your outgoing e-mails are not marked as spam. You can start here: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-postfix-e-mail-server-with-dovecot

– nKn – 2015-11-11T19:40:16.550