Showing posts with label sendmail. Show all posts
Showing posts with label sendmail. Show all posts

Friday, 17 May 2013

Use HTML pre tag to keep email display format

In my servers, I have some shell scripts to send system status reports to my email address.
It's very easy to implement, just run script to generage the report and send the report using sendmail, mail, or mailx.

e.g. if I need to email the output of w, I can simply put it in this way:
w | mail linuxscripter@myemail.com

but it doesn't have any subject, To fields.

Personally I prefer sendmail, so I added the email headers in this way.
(cat <<EOF
From: linuxscripter@myserver.com
To: linuxscripter@myemail.com
Subject: output of w

EOF
w)| sendmail -t

This looked pretty ok, and the email displayed nicely in my outlook express 5.

But in 2006, my company upgraded email client to outlook express 6, all the report format were gone, things should appear in the same column didn't.

How should I preserve the report format when displayed in outlook express 6?
I worked as a PHP web developer for 3 years, so the first thing came to my mind is html <pre> tag.
To use html tag in email, I need to set the email MIME type as text/html

This was how I did.
(cat <<EOF
From: linuxscripter@myserver.com
To: linuxscripter@myemail.com
Subject: output of w
Content-Type: text/html;

EOF
echo "<html><pre>"; w; echo "</pre></html>")| sendmail -t

My email reports became nicely formatted again!

Saturday, 7 April 2012

Sendmail: Prvent your SMTP servers from being blacklisted or graylisted

Sometimes we need to send email updates to millions of customers, the customer may register using their office email or public email like yahoo.
If you send a huge amount of emails in a short period of time, you may risk your SMTP servers beging blacklisted or graylisted.

There are a few ways to ensure your email server's functionality.

1. Use sendmail's greet_pause
In sendmail.mc, define greet_pause as 500 mili seconds.
FEATURE(`greet_pause',500) 
update sendmail.cf:
m4 sendmail.mc > sendmail.cf
restart sendmail service:
service sendmail restart
By defining greet_pause as 500, you are telling your email server to pause for 500 mili seconds before responding to any EHLO request. So it can control the rate you send email to outside world, preventing you from flooding outside email servers.

2. rotate IP addresses of your SMTP server periodically.
Suppose you are assigning management IP to eth0, you can define eth1 as the default outgoing IP address, 192.168.100.101, 192.168.100.102, 192.168.100.103 are reserved for eth1, you can write script as cron to rotate them every day.

But you have to make sure these two things:
  • These 3 IP addresses are translated to 3 different public IPs on your router or firewall.
  • The 3 IPs are legitimate addresses to send out email for domain in your header FROM, you need to define you dns records and reverse resolution properly. Otherwise your mails may be rejected by other servers.

Note: A few years ago, I manged 20+ email servers as part of my work, every day we need to send out tons of emails. Customers register to receive email updates from us, I am not a spammer :)