Sendmail forwarding?

Solution 1:

Install Prerequisites

apt-get install sendmail mailutils sendmail-bin

Create a Gmail Auth File

Create the actual directory for the auth file

mkdir -m 700 /etc/mail/authinfo/
cd /etc/mail/authinfo/

Create the auth file itself

vi /etc/mail/authinfo/gmail-auth

Put this in the contents of gmail-auth (make sure to put in the correct user/gmail/password(Also leave the prefixes U:user I:email P:password))

AuthInfo: "U:root" "I:YOUR GMAIL EMAIL ADDRESS" "P:YOUR PASSWORD"

Next you want to create the hash map for the authentication file

makemap hash gmail-auth < gmail-auth

Configure Your Sendmail

Add the following block of code right above first "MAILER" definition line

define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl

Next you have to compile the sendmail configuration.

make -C /etc/mail

Restart sendmail to pick up the changes

/etc/init.d/sendmail reload

Configuration Test

echo "Just testing my sendmail gmail relay" | mail -s "Sendmail gmail Relay" [email protected]

At this point you should have the relay working. Now we will move on to the virtusertable.

Virtusertable

In order to create virtusertable mappings, you must first create a text file in the /etc/mail/ directory of your server. Each entry in a virtusertable should be on a single line. The original recipient address on the left hand side, with one or more spaces or tabs separating it from the right hand side, which contains the destination address.

Example:

vi /etc/mail/virtusertable

[email protected]    [email protected]
@domain.com        [email protected]

Any time you make a change to the /etc/mail/virtusertable text file, you will need to create a db file that sendmail can read. The following command will create the /etc/mail/virtusertable.db file when run by root:

makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable

Now restart sendmail and all should be functioning as expected.

/etc/init.d/sendmail reload