Hello, please sign in or register
You are here: Home

SendMail an Email server

Its always the way, either know something implicitly, or dont know it.

This is how i feel about SendMail. urgghhh. Partly because i cant find a simple guide of 'How to mail'.

So anyway this is what i want to achieve, my goals, as it were, of a mail server.

1. Able to send mail to any address without it being percieved as crap spam.

2. Be able to receive emails on an email address of my choosing frustrated@perplexed.co.uk as an example, have my mail stored on the server and be able to read my inbox from say Outlook.

3. Secure the mailserver to stop people using it to send their mail. This is a trick i used to do at University, bounce mail off servers, so i never needed to settup my own. Until now.

 

Getting Started

SendMail: appropriately named, comes bundled with fedora core and on my configue its included and i can check its running by typing...

su -
# password prompt
service sendmail status
# returns 'yes i'm on mon'

Which either returns somethin nice or somethin nauseating.

MX-Record

So now we draw our attention to setting up something called MX-Record which is an accronym for Mail eXchange, which does indeed sound alike a dating service. Stay with me.

I, along with many others, collectively manage 3 million domains registered through 1&1 domain hosting. So if your one of these this might be useful else skip this bit.

[IMG=1]fig.1: 1&1 screen shot of MX-Server settings[/IMG]

If you click 'Package Administration' > 'Domain' and then the site domain, check the check-box and click the 'DNS settings' you can edit the IP Server location and mail settings known as A-Record and MX-Record. Fig 1 Shows my current settings for the domain dodsons.co.uk, my family surname, ahhhh i hear people defecate, yuk.

So now this is set. I can check that everything is working through a recommended DNSstuff site aka DNSstuff.com. If you spy the main page there's a collection fo tools including an email tester. I submitted "mail.dodsons.co.uk" which i have not configured as a recognised email address on my server, nevertheless incured the response..


Getting MX record for dodsons.co.uk (from local DNS server, may be cached)... Got it!



Host	Preference	IP(s) [Country]

dodsons.co.uk.	10	83.151.196.41 [UK]





Step 1:  Try connecting to the following mailserver:

         dodsons.co.uk. - 83.151.196.41



Step 2:  If still unsuccessful, queue the E-mail for later delivery.



Trying to connect to all mailservers:



   dodsons.co.uk. - 83.151.196.41  [Could not connect: Could not connect to mail server 

(connection refused by remote mailserver).  NOTE: Per the RFCs, mailservers are allowed to 

continuously retry this server until it is back online, and not try other MX records (RFC2821 3.9

I checked this out with some of my other domains, which i had not configured in 1&1 tools. Sure enough these all went to 1&1's mail servers. So my change in settings worked almost immediatly,whether i set them correctly is another matter

I ran the following script on my server for my server alias dodsons.co.uk.

[username@strawberry mail]$ host dodsons.co.uk
dodsons.co.uk has address 83.151.196.41
dodsons.co.uk mail is handled by 10 dodsons.co.uk.

... Hazzaaar!

Sending Email

I was able to send an email from my server to "someemail@somedomain.com" using this script

echo "test" | mail -s testsubject someemail@somedomain.com

The email i recieved had all the gubbins of a usual email and the address it came from

supermoto@strawberry.dodsons.co.uk

. strawberry.dodsons.co.uk ,is the name of the server i was sending my email from.

 

Configuring
/etc/mail/sendmail.mc

The file sendmail.mc is an editable configuration file for SendMail. It actually creates the file sendmail.cf which is the configuration file used by the program. But unless you want to get burnt dont ever edit sendmail.cf, apparently. To update the config file run make within the directory.

First of all there's a few other commands to refresh the mail configuration scripts... so make a bash script to simplify execution

/etc/mail/compile

#!/bin/bash
cd /etc/mail
make
newaliases
/etc/init.d/sendmail restart

To call this bash script

bash /etc/mail/compile

Ensure its all chmod'd with 700 or alike.

Additions

Open up

/etc/mail/sendmail.mc

and insert the following lines, note i dont think it matters where thewy go, i put mine at the top so i could easily see what i had altered

...

dnl ***** Customised section 1 start *****

dnl

dnl

FEATURE(delay_checks)dnl

FEATURE(always_add_domain)dnl

FEATURE(`masquerade_entire_domain')dnl

FEATURE(`masquerade_envelope')dnl

FEATURE(`allmasquerade')dnl

MASQUERADE_AS(`dodsons.co.uk')dnl

MASQUERADE_DOMAIN(`dodsons.co.uk')dnl

MASQUERADE_DOMAIN(localhost)dnl

MASQUERADE_DOMAIN(localhost.localdomain)dnl

FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl

GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl

EXPOSED_USER(`root')dnl

dnl

dnl

dnl ***** Customised section 1 end *****

... 

In this file rows which are prefixed with 'dnl' are escaped, i.e. commented out

The line MASQUERADE_AS(`dodsons.co.uk')dnl and the following line MASQUERADE_DOMAIN(localhost)dnl, set the default 'From' field that emails sent from the server include. Although you can overwrite this in any scripting language, its nice to define a default, other than the name of the server, which is often meaningless to the email recipient.

Notice that the directives start with a grave mark ` and end with a single quote '.

If send a mail now see Sending Email the recipient from email field will be

user@dodsons.co.uk

 

Alterations

If we run the shell script

telnet dodsons.co.uk 25

It wont be able to connect. Because of a line in the current configuration file which stops the mail server working! "huh!" exactly!

Find the line in /etc/mail/sendmail.mc

...
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

Either remove this line or escape it with the prefix characters 'dnl'. It should looks like...

dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

Run the compile script we created bash /etc/mail/compile, then check that everything works with telnet dodsons.co.uk 25

Read Mail

To display the emails sent in your inbox, run...

mail -u username

Multiple domains, groups and aliases

Alias VirtualUserTable

The alias file is used to send emails prefixed with an unknown user to a user on the linux system. For example, the ensuing code will send emails for

groovy@dodsons.co.uk

to 'drew'

/etc/mail/virtusertable

 

# email         user

groovy@dodsons.co.uk       drew

# other aliases go on sperate lines

Multiple Domains

Allow your email server to recieve emails with different host addresses

E.g. The below example allows you to recieve emails from the domains mysite.com and myothersite.com

Sent Mail

Sent mail, store the emails you have sent, i have googled this many times but cant find a configuration of SMTP to store sent mail in a 'Sent Items' folder. The work around...

Send all out going mail back to yourself by including your email address in the BCC header. You will need to filter out the emails and place into relevant user folder, 'Sent Items'. When Sendmail recieves emails it first checks and executes any comand in the .forward file which sits in the users home directory. http://marginalhacks.com/Hacks/pemf/

External References

Comments

Title*
Comment

Prove you are not a robot

To prove you are not a robot, please type in the six character code you see in the picture below
Security confirmation codeI can't see this!
Contact
Name*
Email never shown*
Home Page

Author

Andrew Dodson
Since:Feb 2007

Comment | flag

Categories

Bookmark and Share