
So, yesterday I was cruising around rent-a-coder to see what I could see, and there I find this fellow who is looking for a PHP coder to do a mail form that will send images to cell phones. I thought to myself "hey, I could do that.. I just have to set up my machine to allow me to test it out". No problem right? BZZT... My wonderful ISP blocks the outbound e-mail (Port 25) so unless I want to send it through their server I am stuck. Now enters gmail. It is possible to easily set up any email program to use gmail as the SMTP server so I figured it would be no problem to set postfix up to do the same. BZZT... I was 0 for 2.
When I did my prerequisite googling, the findings were sparse. Lots of people having trouble setting it up and almost no help in site for anyone. I finally found Mike Chirico's article on just this exact issue. The difficulty with his article though is that it is full of information I was not concerned. He took the user from compile to configure. On top of this, his installation seems to be on a slackware or gentoo machine because the locations of the tools he used are a little different, making it a little more difficult. In this article I will take you from apt-get to configure for Ubuntu 6.10 and add a little bit of guidance in places where another debian based distribution might have tools in other locations. Very little prior knowledge is assumed for this article. For those of you who are more experienced than the level presented, please be patient.
The scope of this document is simply to configure Postfix on Ubuntu 6.10 to be able to send SMTP messages. This is useful for outbound e-mails and php installs that have the developer wanting to send php mail. If you want to be able to receive messages using something like fetchmail, I refer you back to Mike Chirico's site for fetchmail configuration.
Here we go....
---------------------------------------------------------
Make sure our system is up to date. Open up a terminal window. You will see a '$' at the left. This is the prompt where you type the commands and in all my command from this point on it will be the left most character. After the first command it will ask you for your password. This should be the password you use to log into your machine. Non-Ubuntu machines will normally use the root user's password, which was determined during the installation of the operating system.
$sudo apt-get update
$sudo apt-get upgrade
We now need to install the tools used to make the connection happen. Gmail requires authentication using a password so we have to make sure to install all the necessary tools. Some questions will pop up while the system installs Postfix, just hit tab and enter for now.
$sudo apt-get install postfix libsasl2 sasl2-bin libsasl2-modules libdb3-util procmail
The previous command installs Postfix (our mail server program) adds sasl and tsl support for postfix (required for postfix to do the encrypted authentication needed by gmail) and procmail which is the Mail Delivery Agent that Postfix uses to rout the email coming into it.
Next we have to reconfigure Postfix so that the configuration file is set up correctly for us. You will be prompted with a series of questions which we will go over here. The answers are in bold.
If you have a domain name (bob.com, or some Dynamic DNS service domain name) for your network, you may put that in place of server1.example.com just make sure it matches what ever you list as your computer in /etc/hosts. Similarly, if you will be using this machine to rout e-mail from other machines on the network, make sure to add those machine names to the answer to "destinations" question and put your network IP (usually 192.168.1.0 check those first 3 numbers using ifconfig in the terminal to be sure though) in at the "local network" question
General type of configuration? Internet Site
Where should mail for root go? NONE
Mail name?server1.example.com
Other destinations to accept mail for? (blank for none)server1.example.com, localhost.example.com, localhost
Force synchronous updates on mail queue? No
Local networks? 127.0.0.0/8
Use procmail for local delivery? Yes
Mailbox size limit?0
Local address extension character? +
Internet protocols to use? all
Now we will run some commands that will put a few more tidbits of info in the file before we add the meat later on. Due to the constraints of the web, that first command may be on two lines.
$sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
$sudo postconf -e 'inet_interfaces = all'
$sudo postconf -e 'broken_sasl_auth_clients = yes'
$sudo echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
$sudo echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf
The last two commands allow Postfix to authenticate users connecting to it.
Before we enter into our configuration file, we have to create a certificate to use when contacting gmail. This certificate is a way for systems on the internet to identify that you really are the person or network that sent the message. Verisign issues these for companies, and they cost a lot of money because financial transactions require more stringent verification than what we will be doing. For our needs, we will make our own.
The first step is to create a Certificate Authority file. Both the server certificate and public key will be built using this file. To start the Certificate Authority generation script In Ubuntu, type:
$sudo /usr/lib/ssl/misc/CA.pl -newca
For other Linux versions the ssl directory may be located in /usr/local/ or /usr/share. Poke around if you cannot launch the CA.pl file using any of those paths.
Once you launch the script you should see this:
CA certificate filename (or enter to create)
Making CA certificate ...
Generating a 1024 bit RSA private key
.......++++++
...................++++++
writing new private key to './demoCA/private/cakey.pem'
Enter PEM pass phrase:
At this point you will have to pick a password that you will need to remember in order to generate the remainder of the files, as well as any other files you might want to make for yourself later on using this CA (pgp keys, apache ssl keys, etc). It will ask you to verify this password to make sure you typed it correctly.
Following the initial creation of the CA file, it will ask you some questions to uniquely identify this certificate. This is what you should see:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
You can make up all this info, but make sure you can remember it as you will need to know it later on. All you need to fill in is the country code, the state (if you are from the US), your city, and the organization name (if it is a multi word name, use underscores for spaces). When you see it ask for your common name, just enter the domain name you used in the postfix configuration (it does not matter what you enter really as long as you enter something), Finally, enter an e-mail when it asks. Everything else can be left blank. This is what you should see on the screen:
Country Name (2 letter code) [US]:US
State or Province Name (full name) [Pennsylvania]:Michigan
Locality Name (eg, city) []:Detroit
Organization Name (eg, company) []:BMS_Industries
If you screw up, you can re-run the CA.pl script but make sure to delete the demoCA directory which will be located in the directory you are doing all this work.
Now that we have created a Certificate Authority file we can make the server certificate and the public key used in the authentication process. To make the server certificate run this command replacing the information in the single quotes with the information you put into your CA file:
$sudo openssl req -new -nodes -subj '/CN=squeezel.squeezel.com/O=BMS_Industries/C=US/ST=Michigan/L=Detroit/emailAddress=BMS@newsvine.com' -keyout FOO-key.pem -out FOO-req.pem -days 3650
CN is the place you put the common name you used, O is the organization name, C is the country, ST is the state, L is the city, emailAddress is... well.. the email address you used. Make sure you enter those items in EXACTLY the way you did above or your key will not authenticate.
What this command does is it creates a certificate key file called FOO-key.pem and a req file called FOO-req.pem. The second file will be used to create the certificate file we will need.
To create the certificate file we issue the command:
$sudo openssl ca -out FOO-cert.pem -infiles FOO-req.pem
This create a signed certificate file that will be used to verify your identity as the originating server. Simply answer yes to the prompts that follow.
Finally copy the certificate files to /etc/postfix and give them the needed permissions:
$sudo cp demoCA/cacert.pem FOO-key.pem FOO-cert.pem /etc/postfix
$sudo chmod 644 /etc/postfix/FOO-cert.pem /etc/postfix/cacert.pem
$sudo chmod 400 /etc/postfix/FOO-key.pem
Now we can go back to our postfix configuration and make some changes to the main.cf file and create some other needed files. From this point out, all the things we are checking are meant to make sure Postfix itself is operational and has nothing to do with the certificates we created above.
Check your computer's hostname by looking in the /etc/hostname file. If you are using another Linux system this may be different (/etc/sysconfig/network or the like). To check the hostname file you can simple type $cat /etc/hostname and it will display the information in the terminal. Using this information, we want to make sure everything knows what the hostname is so run the command $sudo hostname bob.com replacing "bob.com" with what ever your hostname file says. This simply makes sure we are in a known state off wellness for the rest of the configuration.
Next move to the /etc/postfix directory, back up main.cf $sudo mv main.cf main.cf.old and open up the main.cf file in your favorite text editor (I think HowTo writers are suppose to say vi to sound cool but you can use gedit or nano if you like):
$sudo gedit main.cf
Copy the following lines to the bottom of your main.cf. Being at the bottom, it will override any settings made at the top that have the same name.
## Add these lines to the bottom on main.cf
##
##
## TLS Settings
#
# For no logs set = 0
smtp_tls_loglevel = 1
#
# smtp_enforce_tls = yes
# Above is commented because doing it site by site below
smtp_tls_per_site = hash:/etc/postfix/tls_per_site
#
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_tls_cert_file = /etc/postfix/FOO-cert.pem
smtp_tls_key_file = /etc/postfix/FOO-key.pem
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
smtp_use_tls = yes
smtpd_tls_CAfile = /etc/postfix/cacert.pem
smtpd_tls_cert_file = /etc/postfix/FOO-cert.pem
smtpd_tls_key_file = /etc/postfix/FOO-key.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
## SASL Settings
# This is going in to THIS server
smtpd_sasl_auth_enable = no
# We need this
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_local_domain = $myhostname
smtp_sasl_security_options = noanonymous
#smtp_sasl_security_options =
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_application_name = smtpd
## Gmail Relay
relayhost = [smtp.gmail.com]:587
## Good for Testing
# sender_bcc_maps = hash:/etc/postfix/bcc_table
# Disable DNS Lookups
disable_dns_lookups = yes
#
# Great New feature Address Mapping
# for example may mchirico@localhost to mchirico@gmail.com
smtp_generic_maps = hash:/etc/postfix/generic
#
#
transport_maps = hash:/etc/postfix/transport
One of the key entries in this stuff is the GMAIL RELAY section. This is the setting that turns our postfix system into a smarthost configuration. This is what we need to use use gmail's SMTP servers. More importantly. we are using port 587 which is not the SMTP port. This is why using gmail to send our outgoing mail is beneficial... ISPs do not block this port. Also notice that we have what appears to be repeated lines for our certificates. If you look closely however, one is smtp the other is smtpd. One is the configuration for the service, the other is the configuration for the client. Finally you can see a number of 'hash:' lines. The top of your config file will have some hash lines as well. Do not worry about those since the initial setup took care of those. The hashes we refer to need to be created still. Lets go do that now.
Setting up the sasl_passwd file and hash is necessary to log into gmail. Remaining in the /etc/postfix directory issue the command:
$sudo gedit sasl_passwd
This creates a new file in /etc/postfix called sasl_passwd.
Place into that file the following:
[smtp.gmail.com]:587 bms@gmail.com:password
The smtp info needs to remain, but you must change the email address and the password to match your own.
Next we need to make a hash file out of this. Enter $sudo postmap sasl_passwd
That is all we have to do to make the sasl_passwd. Equally exciting is that the other hash files are just as easy to make.
Next create the generic file and hash using the same methods in the last section with this inside:
bms@squeezel.bob.com bms@gmail.com
replace bms@bob.com with your username on your linux box before the '@' sign and your hostname after the '@'. Similarly, replace 'bms@gmail.com' with your gmail address.
Now we need to make the transport file and hash. This is the file that tells postfix how to rout emails it gets.
Open a new text file called transport and enter into it:
# This sends mail to Gmail
gmail.com smtp:[smtp.gmail.com]:587
#
# Except mail going to the tape and closet server
comp1.bob.com relay:[comp1.bob.com]
comp2.bob.com relay:[comp2.bob.com]
What this tells postfix is to send all mail to gmail except for two cases. On my network I have two other computers. One called comp1 the other called comp2. I am telling postfix to send email meant for those two computers directly to them.
Remember to make the hash for the transport file.
We now need to create the tls_per_site file and hash. This is possibly the most important file to create after the main.cf. This file will protect us from "man-in-the-middle" attacks by forcing a secure connection to the remote machine BEFORE we send any passwords.
Create the file tls_per_site and enter:
smtp.gmail.com MUST
comp1.bob.com MUST
comp2.bob.com MUST
p>
Replacing my domains with your domains and making the hash with postmap.. yada yada. The 'MUST' keyword tells postfix to establish a secure connection with those domains before doing any password hanky panky. If you do not want to worry about your local network because it is small like mine and does not rely on wireless networking, then you can use the keyword MAY. Gmail is a MUST however.
Open master.cf using $sudo gedit master.cf and find the line that reads relay unix - - n - - smtp. It will be a little ways down. Beneath that line, you will probably see a few settings that start with '-o', we will be adding one more. Enter -o smtp_generic_maps= right below the relay line. This entry tells postfix to send out your emails with your gmail address as the originating address rather than your Ubuntu account and domain. When ever you edit the master.cf file you need to reload postfix. To do this simply issue the command$sudo postfix reload.
That is all there is to it. Make sure your postfix server is started by typing $sudo postfix start. You should now have a working postfix server that sends messages out through gmail's smtp servers. Test it out and make sure it works.
Note: If you check the mail.log file you might notice that your certificate is not validating with gmail. I have not found a reason for this yet but it doe snot seem to impede the function
To fix the errors in you mail.log file follow These Instructions. However, replace Thawte_Premium_Server_CA.pem with Equifax_Secure_CA.pem
If you are experiencing any problems, please read through the comments section. Many problems have been asked and answered and the solution may exist there.
This doesn't look like a very Ubuntu-like howto. Perhaps you're aiming at the wrong audience. :)
I mean that Ubuntu is marketed as the distro that "just works". It's meant to be easy to use, and it's primarily aimed at people who don't want to mess with a command line. The typical Ubuntu user (at least judging by the intent of Ubuntu) would be shocked that they have to type in these arcane commands to do something. Where's the GUI? You don't even use the Ubuntu package manager to install programs.
It just doesn't seem to fit with the Ubuntu way of doing things.
Perhaps Ubuntu is more popular among power users than I thought. Maybe it's the combination of apt-get and a distribution that actually has current software. Still, I had the same problem with Ubuntu that I've had with almost every distribution: everything works great until you try to install some software that isn't part of the distribution. Then all hell breaks loose.
Every time I try to help someone through that problem I'm reminded why Gentoo is worth it in the long run.
Yeah, that's why I said "long term". Gentoo takes a very long time to install and get everything just right, but once you've done that everything is much cleaner and easier to manage. The only problem then is if you get new hardware and don't have the kernel set up for it.
The problem I was talking about is if you try to install something that doesn't exist in the distribution. Finding a binary package for a particular distribution is often very hard (and you never know if you can trust the one you get). Installing a binary for a different distribution is likely to fail because the dependencies are wrong. Instead of foo-2.6.3-5, you have foo-2.6.3-2a. You can force install, but then your system is in a questionable state.
Then you have the choice of installing from source, but unfortunately distributions like Ubuntu aren't very friendly to this method. They don't install development headers by default, so you have to track down all the -devel packages that you need (usually by running configure, seeing a failure, installing the missing package, then repeating until configure works). Then, with my luck, one of the development packages I need isn't in the distribution either, so I have to install that package from source as well. Then I repeat all the above steps for a different package.
I've literally spent hours trying to install a single package before giving up. That's bad enough one time, but this has happened to me for 3 or 4 different distributions. It's just too annoying to deal with.
Everything is source-based in Gentoo, so if the package isn't in the repository then you can easily install from source without a problem. And portage is such a beautiful package manager for source-based stuff. You can turn features on (like kde support) across all packages in a global config file.
I'm not evangelizing, though. I don't recommend Gentoo to people who aren't experienced Linux users who don't mind doing things "the hard way". It's a very clean distribution, but it's aimed at an entirely different group of people.
Hello,
Nice article. Very clear and concise steps. I already had Postfix installed, so I simply jumped to step 6 and had my configuration working in about ten minutes.
You might want to post this as an official HOWTO in the ubuntuforums. I'm sure many folks would find this useful.
I'll be keeping an eye out for your articles in the future.
thanks for the how-to. it is very well writen and helpful. I followed the steps and everything apeared to work. I'm still having problems, though. (bear with me, I'm a newbie)
I then tried to send a test message with echo test | mail -s subject stephenkilbourn@gmail.com
(I also tried to krull.etc@verizon.net) but it appears that something's not set up correctly for my secuirty certificate. Can you help me? the mail.log is below:
Feb 7 23:43:57 krull-desktop postfix/pickup[8151]: 03A8110E419: uid=1000 from=
Feb 7 23:43:57 krull-desktop postfix/cleanup[8590]: 03A8110E419: message-id=<20070208054357.03A8110E419@gmail.com>
Feb 7 23:43:57 krull-desktop postfix/qmgr[8152]: 03A8110E419: from=<krull@gmail.com>, size=295, nrcpt=1 (queue active)
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: setting up TLS connection to smtp.gmail.com
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: certificate verification failed for smtp.gmail.com: num=20:unable to get local issuer certificate
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: SSL_connect error to smtp.gmail.com: -1
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: warning: TLS library problem: 8592:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:894:
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: 03A8110E419: Cannot start TLS: handshake failure
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: setting up TLS connection to smtp.gmail.com
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: certificate verification failed for smtp.gmail.com: num=20:unable to get local issuer certificate
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: SSL_connect error to smtp.gmail.com: -1
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: warning: TLS library problem: 8592:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:894:
Feb 7 23:43:57 krull-desktop postfix/smtp[8592]: 03A8110E419: to=<stephenkilbourn@gmail.com>, relay=smtp.gmail.com[64.233.167.111]:587, delay=0.52, delays= dsn=4.7.5, status=deferred (Cannot start TLS: handshake failure)
Great Work Buddy.
Very useful and expressive
Nice HOWTO, but I'm getting the same failures as Krull... E-mail deffinately not geting though...
But I did get these errors in step 4:
tim@vorlon:/etc/postfix$ sudo echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
bash: /etc/postfix/sasl/smtpd.conf: Permission denied
tim@vorlon:/etc/postfix$ sudo echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf
bash: /etc/postfix/sasl/smtpd.conf: Permission denied
Any ideas? Can't understand how sudo gets me a permission dennied...
Kosh42|EFG:
The problem you're experiencing is due to the subtlety of the shell. when you type that command, the shell is actually doing two things:
(1) it is opening /etc/postfix/sasl/smtpd.conf for append. It does this as the user 'tim'
(2) it is executing the following command "sudo echo 'pwcheck_method: saslauthd'".
Since shell attempts to open the smtpd.conf file user tim, it fails since tim doesn't have write permission on that file.
The best way to do this is probably just to get a root shell, then do your command:
$ sudo -s
# echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
This way when the shell does (1) and (2) form above, it is doing them both as root, who has permissions.
Hope this helps.
Great howto... its sad that this stuff is so complicated still though... just doesn't seem right.
I was having the same problem as krull above. Found th solution at
"These warnings are because postfix doesn't know where to find the Thawte
certificate that gmail used to sign its own certificate. Ubuntu
includes it in its ssl package. You need to append it to the
cacert.pem file you generated earlier.
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem >> cacert.pem "
Worked like a charm :P
Hi & thanks for the great work!
Still I have 1 question -
I'm trying to send email with
telnet mail.yourdomain.com 25
ehlo yourdomain.com
mail from: root@yourdomain.com
rcpt to: fmaster@yourdomain.com
data
Subject: My first mail for my domain
Hi,
Are you there?
regards,
Admin
. (and Enter In a new Line)
quit
(This was taken from )
So after
rcpt to: val***@gmail.com
i get:
554 5.7.1 <val****@gmail.com>: Relay access denied
Please help?
"Note: If you check the mail.log file you might notice that your certificate is not validating with gmail. I have not found a reason for this yet but it doe snot seem to impede the function"
----------------------------------------------------------------------------------------------------------------------------
For me, i was not able to send mail because gmail cannot validate the tls certificates.
I was searching for a while and i found this howto, similar to this howto, plus the solution to the validating the certificates from gmail:
the howto is in:
the section pointing the problem is this:
"One difference from the tutorial: when running postfix, you may get warnings like this one:
Jan 4 17:21:59 calvin postfix/smtp[28881]: setting up TLS connection to
smtp.gmail.com
Jan 4 17:21:59 calvin postfix/smtp[28881]: certificate verification failed
for smtp.gmail.com: num=20:unable to get local issuer certificate
Jan 4 17:21:59 calvin postfix/smtp[28881]: SSL_connect error to
smtp.gmail.com: -1
I've copied them in so people searching for them will find this. These warnings are because postfix doesn't know where to find the Thawte certificate that gmail used to sign its own certificate. Ubuntu includes it in its ssl package. You need to append it to the cacert.pem file you generated earlier.
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem >> cacert.pem"
so, after i follow the behindmyscreen howto i run the command:
sudo cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem >> cacert.pem
but even with sudo, i have a permition denied error.
the runaround who worked for me:
sudo cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem
copy the certs and
sudo nano /etc/postfix/cacert.pem
and paste the certs at the bottom of the file
save the file
restart postfix
sudo postfix reload
and you can see now in /var/log/mail.log that the gmail validate the tls certs
after that i am able now to send mails thru the gmail smtp server
OK, this (the copy and paste of the Thawte cert into cacert file) got the certificate validation error resolved. For others, if you don't find the Thawte certs in /etc/ssl/certs then this should resolve it:
apt-get install ca-certificates
Now that I'm getting the TLS connection to gmail, however, smtp.gmail.com is denying my credentials (SASL authentication failed; server smtp.gmail.com[209.85.133.109] said: 535 5.7.1 Credentials Rejected c20sm12059077ana.13). Is Google closing up the relay?
I have clearly been affected by the past 2 days of banging my head against sendmail and more recently postfix... I had mis-entered information in the sasl_passwd file, which fixed the final final final problem with credentials.
A sincere thank-you to all who contributed to this article- it was the last trigger I needed to get it all moving...
Just a quick note to say thanks. I've been trying to get this to work for 2 days before stumbling across this howto. This is a life saver.
great how-to! i was wondering if there was a way to set up postfix to use a different gmail address depending on which website the email might be originating from? for example, if i have site1.com and site2.com running as virtual hosts on my machine is there a way to ensure that the email gets sent such that site1.com sends from site1@gmail.com and site2.com sends from site2@gmail.com?
thanks!
This helped me very much to get this working on a ClarkConnect box. Thanks very much!!! But what do I need to change in order to use multiple GMail senders? Since my girlfriend and myself use the CC box now and for both GMail addresses the mail needs to be relayed. The mail gets relayed, but with my gf's name, but my e-mail address. Please help!!
I am having the same problem as Angelo-235665 - I suspect the issue is in the generic file, the master.cf file, or the aliases file.
I would like to use PHP to send mail, but override the "from" and "reply-to" headers to be able to send from any e-mail address. and not just the one specified in the sasl_passwd file
Any help would be appreciated - thanks!
I found this: #fantasy and it shows how to use multiple relay-hosts within postfix. Sadly (for me), this only works from version 2.3 and my ClarkConnect box still uses 2.2.7. I'm not sure if i'll break CC if I upgrade postfix manually.
Some snooping around reveales that GMail rewrites the header with regards to the sender to the address with which was logged into the STMP server even when there was another address. So when my gf sends an e-mail, even though the info is from her account, postfix uses my login credentials, so GMail rewrites the header with my e-mail address.
I found a site which explains how to setup multiple running copies of Postfix, I think this is what you mean? Of course I can't find the site now.
In version 2.3 and higher one could fix it with an option called sender_relay where there sending address is connected to a relay host and then with the correct login.
I haven't tried this with the reply-to yet, but in a way this is not really what one would want, since it looks a little 'weird' in the e-mail at the recipient end :)
Oeps, I can't put URL's here.... Perhaps like this: postfix.org / SOHO_README.html#fantasy (okay, just remove the spaces) :) Good luck if you have 2.3
Btw, be carefull when you use this in combination with a generic and/or transport file. It could also be offcourse because I was using a old version, but while hacking away at this, all my incoming mail started getting relayed automaticly. GMail didn't like that one bit and blocked me for a day :(
Thanks!
I got it working following the instructions on this site.
I have one issue though: I can send emails to anybody whether to a gmail address or else, except to my own gmail address.
by doing
sendmail -i mywifeemailaddress@gmail.com
test
[ctrl D]
my wife receives the email
sendmail -i myemailaddress@gmail.com
test
[ctrl D]
the email is never received.
/etc/log/mail.log indicates success everytime
Any suggestion?
I was getting a TLS handshake failure. To fix it I had to change the line in the tls_per_site file to :
Original
smtp.gmail.com MUST
p>
Modified
smtp.gmail.com MAY
This apparently reduces the security but it works.
Hey BMS
Thanks a lot man. This is an amazing solution. This works like a charm for google apps as well.
Hi i have the problem that my postfix doesn't send the mails 'cause of the status which shows "Server certificate not trusted"
what can do against this?
Great HOWTO got it working in about 10 minutes with your directions
Question?? I'm want to do some advanced relaying. I have multiple email domains hosted by Google Apps.
I have postfix 2.3.3 installed. I've added the line.
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay
sender_relay file has...
user1@mydomain1.com[smtp.gmail.com]:587
user2@mydomain1.com [smtp.gmail.com]:587
user3@mtdomain1.com[smtp.gmail.com]:587
##the other domain
user4@mydomain2.com [smtp.gmail.com]:587
user5@mydomain2.com [smtp.gmail.com]:587
and
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
[smtp.gmail.com]:587 user1@mydomain1.com:password
[smtp.gmail.com]:587 user2@mydomain1.com:password
[smtp.gmail.com]:587 user3@mydomain1.com:password
[smtp.gmail.com]:587 user4@mydomain2.com:password
[smtp.gmail.com]:587 user5@mydomain2.com:password
my main.cf file looks like this
mtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_tls_cert_file = /etc/postfix/FOO-cert.pem
smtp_tls_key_file = /etc/postfix/FOO-key.pem
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
smtp_use_tls = yes
smtpd_tls_CAfile = /etc/postfix/cacert.pem
smtpd_tls_cert_file = /etc/postfix/FOO-cert.pem
smtpd_tls_key_file = /etc/postfix/FOO-key.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
## SASL Settings
# This is going in to THIS server
smtpd_sasl_auth_enable = no
# We need this
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
#smtp_sasl_password_maps = mysql:/etc/postfix/sasl_passwd_mysql
smtpd_sasl_local_domain = $myhostname
smtp_sasl_security_options = noanonymous
#smtp_sasl_security_options =
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_application_name = smtpd
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
# Server hostname and domain name
myhostname = mail.mydomain.com
mydomain = mydomain.com
# Our Virtual users and aliases tables
#virtual_mailbox_base = /
#virtual_mailbox_maps = hash:/etc/postfix/virt_users
#virtual_alias_maps = hash:/etc/postfix/virt_aliases
# Local Recipients maps
#local_recipient_maps =
#$virtual_mailbox_maps,
#$virtual_alias_maps,
#$transport_maps,
#unix:passwd.byname
# Our local users map
#alias_maps = hash:/etc/postfix/aliases
#alias_database = hash:/etc/postfix/aliases
# Server Information
myorigin = /etc/mailname
mydestination =
localhost
# Gmail Relay
relayhost = [smtp.gmail.com]:587
#Allowable LAN clients/servers
mynetworks = 127.0.0.0/8 192.168.0.0/24
#client settings
mailbox_size_limit = 0
recipient_delimiter = +
disable_dns_lookkups = yes
smtp_sender_dependent_authentication = yes
#sender_dependent_relayhost_maps = hash:/etc/postfix/relayhosts
# Great New feature Address Mapping
# for example may mchirico@localhost to mchirico@gmail.com
#smtp_generic_maps = hash:/etc/postfix/generic
smtp_generic_maps = mysql:/etc/postfix/generic_mysql
#
# Transport maps
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
thank you
And again great article
I think this would be a great howto for advance postfix usage
This really looked good at first, but I soon became disillusioned because Step 3 assumes I know how and where to answer the questions listed. Please explain!!
OK. I just spent the last hour messing around with this and still no email. All together I have spent over 20 work-hours trying to get ubuntu server to send an email - no success yet.
Dittos to the person who wishes setting this up was a little bit more straightforward.
So I added another hour to my 20+ working-hour struggle to send email from ubuntu server.
Still no success. I have yet to send one single email from my ubuntu server. Dittos to that person who wishes that setting this stuff up was more straightforward.
If I didn't read y'all's success stories, I would not believe that doing this was really possible.
You're in Easy Mode. If you prefer, you can use XHTML Mode instead. |