Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This is a rather long question with a long list of things tried and travails so please bear with me. The summary is this.

  1. I am able to relay email from ubuntu through office365 using postfix; the configuration works.
  2. It only works as one of the users; more specifically the user who authenticates against office365 is the only valid "from"

More details follow. I have a machine in Amazon's cloud on which I run a bunch of jobs and would like to have statuses mailed over to me. I use office365 at work so I want to relay mail through office365. I'm most familiar with postfix so I used that as the MTA.

Configuration is ubuntu 12.04LTS; I've installed postfix and mail-utils.

For this example, let me say my company is "" and the machine in question (through an elastic IP and a DNS entry) is called "". hostname is set to "", so is /etc/mailname

On plaything, I have the following users registered alpha, bravo, and charlie.

I have the following configuration files.

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
inet_protocols = ipv4
mailbox_size_limit = 0
mydestination =,, , localhost
myhostname =
mynetworks = [::ffff:]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost = []:587
sender_canonical_maps = hash:/etc/postfix/sender_canonical
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_use_tls = yes
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes

As the machine is called I went through the exercise of registering all the appropriate DNS entries to make office365 recognize that I owned and allowed me to create a user called in office365.

In office365, I setup as having another email address of

Then, I made the following sender_canonical

I created a sasl_passwd file that reads:

let's just say that the password for is 1234...456

With all this setup, login as alpha and

Subject: test

and the whole thing works wonderfully. email gets sent off by postfix, TLS works like a champ, authenticates as daemon@... and in Office365 gets an email message.

The issue comes up when logged in as bravo to the machine.

sender is and office365 says:

status=bounced (host[] said: 
550 5.7.1 Client does not have permissions to send as 
this sender (in reply to end of DATA command))

this is because I'm trying to send mail as bravo@... and authenticating with office365 as daemon@.... The reason it works with alpha@... is because in office365, I setup as having another email address of

In Postfix Relay to Office365, Miles Erickson answers the question thusly:

  1. Don't send mail to Office365 as a user from your Office365-hosted e-mail domain. Use a subdomain instead, e.g. instead of It wouldn't hurt to set up an SPF record for or whatever you decide to use.

  2. Don't authenticate against as an Office365 user. Just connect on port 25 and deliver the mail to your domain as any foreign SMTP agent would do.

OK, I've done #1, I have those records on DNS but for the most part they are not relevant once Office365 recognizes that I own the domain.

Here are those records:

CNAME records: - -

MX record: - (

TXT record: - (v=spf1 -all)

I've tried #2 but no matter what I do, office365 just blows away the connection with "not authenticated". I can try even a simple telnet to port 25 and attempt to send and it doesn't work.

250 Hello [] 
530 5.7.1 Client was not authenticated 
Connection closed by foreign host.

Is there someone out there who has this kind of a configuration working where multiple users on a linux machine are able to relay mail using postfix through office365? There has to be someone out there doing this who can tell me what is wrong with my setup ...

share|improve this question
If you're sending email from postfix TO a user IN your Office365 hosted domain then you are not relaying. You are simply sending an email to an Office365 hosted email domain/user just as I would if I sent an email to your Office365 hosted email address. Relaying occurs when you want to send an email from postfix to a non-Office365 hosted domain THROUGH Office365. So which one are you trying to accomplish? – joeqwerty Sep 10 '13 at 0:49
@joeqwerty I am attempting to send email to multiple users, some would be in my office365 domain and some would be not in my office365 domain. I illustrated above with users in the office365 domain because as best as I can tell, there is no difference in behavior of office365 in that regard; it objects to the sending of an email message with a <from> address that IT cannot map to the authenticating user. In this example, the fact that, and are the same thing is what makes it work in one case but fail with bravo@... – amrith Sep 10 '13 at 0:54
@amrith - I don't know Postfix, but I do have anon relay working through our O365 account in Windows. If you want details that should be applicable to Postfix, let me know. Otherwise, I'll let the Postfix experts answer. – TheCleaner Oct 8 '13 at 1:35

1 Answer 1

I think you need to take a step back :)

If you are logged into plaything as bravo, do you really need all mail sent from plaything to be sent as If not, simply send all mail as, see Postfix on hosts without a real Internet hostname.

If you cannot apply this, then you will need Sender dependent SASL maps. It will add some complexity to your setup, so I'd really try hard to avoid this.

Last but not least, if plaything would send mails as, you'd need to adjust myhostname and/or myorigin as well as get rid of the relayhost setting. In this case, plaything would deliver all mail directly, with all the pros and cons like mail server reputation and so on.

share|improve this answer
your first comment is an interesting one. (if logged in as bravo can email just go as daemon?). it would be great if I could get wildcards in sender_canonical to work. enumerating each user is a pain.<br /> Sender dependent SASL maps seems to be the perfect solution; I will try it. I was hoping someone could tell me how to make relaying without authentication work with office365. After all, remote MTA's have to deliver mail to office365 and they don't authenticate. It may be more of an Amazon SES setup issue, maybe? – amrith Sep 11 '13 at 10:40
See the first link, the last entry within smtp_generic_maps will get all mail to a single sender. And the last paragraph in my answer is exactly why other mailservers can deliver to Office365 - provided they don't use a sender address that belongs to Office365. – Stefan Förster Sep 11 '13 at 11:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.