Sending email from a dynamic IP address

If you want to run a mail server on your Debian server at home then you are probably on a dynamic IP address (one that changes once a day) from your internet provider. The problem with dynamic IP addresses is that they are blacklisted by most mail servers on the internet. You cannot send email directly to other mail servers and need to send your email through a server that is not blacklisted. In this case you just need two things:

  • You need to send out emails through your ISPs mail relay. If they don't offer such a service you can still try to find a commercial SMTP relay elsewhere on the internet.
  • Your ISP must not block SMTP (TCP port 25) connections to your IP address. If they do you cannot be sent emails from other mail servers.

Without these prerequisites I suggest you get an inexpensive VPS (virtual private server) and run the mail server from there.

Sending out email through your ISP is not that hard. Your ISP very likely offers an SMTP server that you can use with a username and a password. If you use their SMTP server from your mail client or from your mail server is technically no difference. So if you can send emails from your mail client then you are set. In your /etc/postfix/main.cf you will have to set:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
relayhost = [name.of.your.isp.relay.server]

(In case you wonder: configuration statements like smtp_* stand for outgoing SMTP while smtpd_* statements are for incoming SMTP connections. So these settings apply to outgoing SMTP connections.)

This sets "name.of.your.isp.relay.server" as the hostname of your ISP's relay server. Of course you need to set the right name here. The brackets means that no DNS lookup for MX records is done. The "relayhost" is the name of the server that Postfix will send all outgoing emails to. Without a "relayhost" Postfix would use DNS lookups to determine which mail server is responsible for a certain domain. The sasl_passwd file is where the username and password will be set that you have to use for authenticating at your ISP's relay server. The file looks like this.

[name.of.your.isp.relay.server]     herbert.ludkins:Ialenuv2

Pretty easy. You name the relay server exactly as in "relayhost", insert a space and then write the username, a colon and the password. Afterwords you need to compile this file as you want to use is as a "hash":

postmap /etc/postfix/sasl_passwd

This will give you an sasl_passwd.db file that Postfix can use.

You can also read about these settings in the Postfix documentation on SMTP authentication.

14 Comments

Relay-Host and getting Mails

I've tried to use the Releyhost-Option for my dyndns Server (A-Record, no MX). But with this described settings I can't get Mails towards this Server an more. Did I do anything wrong? Here's the Log from the "outer" Mailserver:

Jun  6 18:38:47 h1762181 postfix/smtp[13317]: D341F22581A9: to=<webmaster@foobar.homeip.net>, relay=foobar.homeip.net[91.23.177.xxx]:25, delay=1.9, delays=0.02/0.02/1.4/0.54, dsn=5.1.1, status=bounced (host foobar.homeip.net[91.23.177.xxx] said: 554 5.1.1 <webmaster@foobar.homeip.net>: Recipient address rejected: User unknown (in reply to RCPT TO command))
 

Reply to mysqlf: Has

Reply to mysqlf:

Has nothing to do with the Relayhost, stranger Effect here:

a) sending locally on the dyndns-Box mails ist OK, everything is fine, but

b) getting mails from "outside" results in user not found errors... whats this?

solved - was a lookup sql

solved - was a lookup sql problem.

i added the active=1 extensions (and table cols also!) but beware in the .cf files: ...

wrong: ... and active=1

right: ... and active='1'

I don't know why but that's it - now everything works fine?!

Postfix Multiple IP & Hostname

Already followed the instruction http://www.linuxmail.info/postfix-multiple-ip-address-smtp-greeting/
I want that each time using 1 SMTP to send email, it just shows the information of 1 IP & 1 host name in the email header. Now I see that it always shows the information of Main IP & Main Hostname.
Detail in https://docs.google.com/document/d/1aCk7vvbP341FR2kd4zXqDVkZlE_8DArUrT6wlOZoiH0/edit
Thank you so much!

530 Authentication required

Hi, I've found some really good stuff on your site, so I was wondering if you could help me out with this.

I did everything like you said, but when I send mail through my Isp to gmail.com It's bounced with 530 Authentication required error.
What I've realized from maillog file, is that my postfix smtp client, after sending 'helo' command goes to 'mail to' command, without authentication. Why is that?

Is 'ehlo' command necessary for authentication process?
My Isp's helo is 220 *************************** (I'm not hiding it, that's what it say) and postfix is not sending 'ehlo' because there is no ESMTP string in it.
I've tried 'smtp_always_send_ehlo = yes' and 'smtp_pix_workaround = ' (enables esmtp, it's disabled by default because of some bug with PIX Cisco routers) and it didn't help.

Am I on a right track? How to make Isp to ask for authentication or to make my postfix smtp client to send it?

I really appreciate your help!

Dejan

I did read that several times

I did read that several times.. Can you point to something in that document that you think it's related with that error?

I've installed cyrus-sasl, cyrus-sasl-lib, cyrus-sasl-plain, cyrus-sasl-sql, cyrus-sasl-devel packages. I've enabled sasl authentication (smtp_sasl_auth_enable = yes), set up a relayhost (relayhost = [my.isp.com]). Command postmap -q [my.isp.com] /etc/postfix/sasl_passwd gives the right answer. Tried setting up sasl type, path... still the same error shows up.

Thank you for trying to help me..

Dejan

Hello,

Hello,
I'm actually running Centos 5, but since this is a Postfix related issue it shouldn't matter. I've installed those packages (CentOS 5 specific ones) because I needed them for SMTP server (smtpd_) authentication. I've enabled dovecot to listen to all, so I'm able to send mails to local users from my mobile. Users are virtual, using cyrus, saslauthd, pam, mysql. Here are the things you've asked:

Maillog:

ov 9 19:44:39 d1 postfix/smtpd[17624]: connect from d1.dcentar.com[127.0.0.1]
Nov 9 19:44:39 d1 postfix/smtpd[17624]: 7AF972FF67: client=d1.dcentar.com[127.0.0.1], sasl_method=LOGIN, sasl_username=dejan@dcentar.com
Nov 9 19:44:39 d1 postfix/cleanup[17633]: 7AF972FF67: message-id=<4437a17d95b09ca14287fea479c4065f@dcentar.com>
Nov 9 19:44:39 d1 postfix/qmgr[17584]: 7AF972FF67: from=<dejan@dcentar.com>, size=9314, nrcpt=1 (queue active)
Nov 9 19:44:39 d1 dovecot: IMAP(dejan@dcentar.com): Disconnected: Logged out bytes=9236/896
Nov 9 19:44:39 d1 postfix/smtpd[17624]: disconnect from d1.dcentar.com[127.0.0.1]
Nov 9 19:44:39 d1 postfix/smtp[17635]: < mail.open.telekom.rs[212.200.12.4]: 220 *********************************
Nov 9 19:44:39 d1 postfix/smtp[17635]: > mail.open.telekom.rs[212.200.12.4]: HELO mail.dcentar.com
Nov 9 19:44:39 d1 postfix/smtp[17635]: < mail.open.telekom.rs[212.200.12.4]: 250 e12mailgw05.open.telekom.rs
Nov 9 19:44:39 d1 postfix/smtp[17635]: server features: 0x1040 size 0
Nov 9 19:44:39 d1 postfix/smtp[17635]: > mail.open.telekom.rs[212.200.12.4]: MAIL FROM:<dejan@dcentar.com>
Nov 9 19:44:39 d1 postfix/smtp[17635]: < mail.open.telekom.rs[212.200.12.4]: 530 Authentication required
Nov 9 19:44:39 d1 postfix/smtp[17635]: 7AF972FF67: to=<gojkovicde@gmail.com>, relay=mail.open.telekom.rs[212.200.12.4]:25, delay=0.14, delays=0.03/0.03/0.07/0.01, dsn=5.0.0, status=bounced (host mail.open.telekom.rs[212.200.12.4] said: 530 Authentication required (in reply to MAIL FROM command))

... and postconf -n

alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
debug_peer_level = 1
debug_peer_list = mail.open.telekom.rs
home_mailbox = Maildir/
html_directory = no
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = localhost
mydomain = dcentar.com
myhostname = mail.dcentar.com
mynetworks = 127.0.0.0/8
mynetworks_style = host
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
relayhost = [mail.open.telekom.rs]
sample_directory = /usr/share/doc/postfix-2.3.3/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain, login
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_path = smtpd
smtp_sasl_security_options = noanonymous
smtp_sasl_type = cyrus
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain =
smtpd_sasl_path = smtpd
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = cyrus
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual_alias, mysql:/etc/postfix/mysql_virtual_forwards.cf
virtual_gid_maps = static:5003
virtual_mailbox_base = /home/vmailer
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailboxes.cf
virtual_minimum_uid = 5003
virtual_uid_maps = static:5003

Thank you for you time, I really appreciate it.

Dejan

I have '[mail.open.telekom.rs

I have '[mail.open.telekom.rs] myusername:mypassword' in it.
I did 'postmap' the file. The command 'postmap -q [mail.open.telekom.rs] /etc/postfix/sasl_passwd' shows myusername:mypassword.