Mobile app version of vmapp.org
Login or Join
Kristi941

: How to set up a mail server on Linux only for sending admin/debug emails? I need to send server reports to myself from my remote servers, and I don't mind them going to spam, so I don't

@Kristi941

Posted in: #Email #Linux

I need to send server reports to myself from my remote servers, and I don't mind them going to spam, so I don't need SPF, DKIM, etc.

I tried using mailutils to send something like this: uptime | mail -s "uptime" foo@bar.com, but the emails don't go through. In /var/mail/root I received a message saying the HELO was invalid. So then I tried also adding -r root@my-ip, and now I don't get any error messages but I don't receive the email either.

How can I do this?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Kristi941

3 Comments

Sorted by latest first Latest Oldest Best

 

@Kristi941

Ok I solved it:

$ apt-get install mailutils
$ vim /etc/postfix/main.cf
myhostname = mydomain.com
$ service postfix restart


Then configure your domain's records to have "mail.mydomain.com" point to your machine's IP, MX record point to "mail.mydomain.com", and also set the SPF using the TXT record like this: v=spf1 include:mydomain.com ip4:1.2.3.4 -all (replace for actual IP)

Now you can send mails with the mail command.

10% popularity Vote Up Vote Down


 

@Speyer207

This can also be done using exim on Fedora/CentOS/RHEL using gmail for SMTP (to build on Stephen Ostermiller's answer using a different distro). You first install exim with yum:

sudo yum install exim


On Fedora 20 this installed version 4.80.1. Once installed you modify the configuration located in /etc/exim/exim.conf and add the following sections to the file:

# in the routers configuration section:
send_via_gmail:
driver = manualroute
domains = ! +local_domains
transport = gmail_smtp
route_list = * smtp.gmail.com

# in the transports configuration section
gmail_smtp:
driver = smtp
port = 587
hosts_require_auth = $host_address
hosts_require_tls = $host_address

# in the authentication configuration section
gmail_login:
driver = plaintext
public_name = LOGIN
client_send = : {your email address at gmail} : {password}


If you use two factor authentication in Google then you must use an app password. Once this configuration is in place you must restart the service for it to take effect:

sudo service exim restart


Once the service starts you can use the mail command, from the command line, to send email using your gmail account.

mail example@example.com
subject: {email subject} <enter>
{message}
.


Where example@example.com is your recipient. The . terminates the message and sends it via exim via Google SMTP using the credentials in the gmail login. If you don't have a gmail account then set one up to get access to the SMTP server. If you have any problems then the logs are saved in /var/log/exim/ in main.log and panic.log for errors.

10% popularity Vote Up Vote Down


 

@Heady270

I use the exim4 email package on Ubuntu configured as a "smart host". This means you give exim4 the user name and password for your normal SMTP server and it will send the email (from commands like mail and sendmail) through that.

Here is the question I asked about setting it up on AskUbuntu.com and the answer that I found:

I finally found a detailed set of instructions by Tony Scelfo that actually work. It appears that you have to use transport layer security (TLS) on port 587. I have not gotten SSL SMTP to work.

First run sudo dpkg-reconfigure exim4-config and use these config options:


General type of mail configuration: mail sent by smarthost; received via SMTP or fetchmail
System mail name: <your hostname>
IP-address to listen on for incoming SMTP connections: 127.0.0.1
Other destinations for which mail is accepted: <your hostname>
Machines to relay mail for: <leave this blank>
IP address or host name of the outgoing smarthost: mail.example.com::587
Hide local mail name in outgoing mail?


Yes - all outgoing mail will appear to come from your gmail account
No - mail sent with a valid sender name header will keep the sender’s name

Keep number of DNS-queries minimal (Dial-on-Demand)? No
Delivery method for local mail: <choose the one you prefer>
Split configuration file into small files? Yes (you need to edit one of the files next)


Then run sudo vi /etc/exim4/passwd.client and add the following lines for your mail host, and any aliases it has (found through nslookup). Substitute <email address> and <password> with the account you want to route mail through):

mail.example.com:<email address>:<password>
mail.yourhosting.provider:<email address>:<password>


Once you edit the passwd.client file, run sudo update-exim4.conf which will integrate your changes into your Exim4 config.

Run sudo /etc/init.d/exim4 restart and make sure that the service stops and starts properly. If the service is unable to restart, something probably went wrong when you edited the passwd.client file.

If Exim4 restarted, go ahead and run sudo tail -f /var/log/exim4/mainlog to watch the mail logs. In a different window, send an email from your system and make sure that you see a record go by withR=smarthost T=remote_smtp_smarthost H=gmail-smtp-msa.l.google.com ... X=TLS-1.0:RSA_ARCFOUR_MD5:16 in it. The X=TLS means that the mail is being sent with transport layer security which is what you want.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme