Author Topic: Outgoing mail is rejected with invalid address format  (Read 2459 times)

nickpiggott

  • Zen Apprentice
  • *
  • Posts: 23
  • Karma: +8/-0
    • View Profile
Outgoing mail is rejected with invalid address format
« on: May 25, 2020, 11:01:27 pm »
Running Zentyal 6.2, Samba Active Directory enabled.

In smb.conf, these values are set
Code: [Select]
workgroup = mydomain  (in lower case)
realm = mydomain.com

From the Linux command line on the server running Zentyal,

Code: [Select]
MYDOMAIN\myuser@dc:\home\myuser$ mail touser@gmail.com
Subject: Test Email
Test Email

The mail is rejected by GMail with this error

Code: [Select]
: host aspmx.l.google.com[108.177.15.27] said: 553-5.1.7 The sender address <MYDOMAIN\myuser@dc.mydomain.com> is not a valid 553 5.1.7 RFC-5321 address.
If I send an email myself, I see TWO mailboxes in /var/mail

Code: [Select]
MYDOMAIN\myuser
mydomain\myuser

When I open mail to read mail, it says there is no mail for MYDOMAIN\myuser
If I cat the file of mydomain\myuser I can see the email

Looking in /var/log/mail.log I can see
 
Code: [Select]
postfix/pickup[29633]: 0532F1403E4: uid=1000 from=<MYDOMAIN\myuser>

So it seems that post fix is doing two things:
  • Not removing the MYDOMAIN part of my username from the outbound "from address"

  • Changing the reply back to all lowercase (including the mydomain section)

Any thoughts what I can do to resolve this?
« Last Edit: May 25, 2020, 11:05:29 pm by nickpiggott »

doncamilo

  • Zen Samurai
  • ****
  • Posts: 478
  • Karma: +165/-1
    • View Profile
Re: Outgoing mail is rejected with invalid address format
« Reply #1 on: May 27, 2020, 06:51:33 pm »
 :)

Google is telling you:

Code: [Select]
: host aspmx.l.google.com[108.177.15.27] said: 553-5.1.7 The sender address <MYDOMAIN\myuser@dc.mydomain.com> is not a valid 553 5.1.7 RFC-5321 address.
MYDOMAIN\myuser@dc.mydomain.com isn't a valid e-mail address.

Try this command:

Code: [Select]
perl -e '$from = "youruser\@youraddress.lan";$to = "someuser\@gmail.com";$subject = "Test Email";$message = "Testing mail";open(MAIL, "|/usr/sbin/sendmail -t") or die $!;print MAIL "To: $to\n";print MAIL "From: $from\n";print MAIL "Subject: $subject\n\n";print MAIL $message ;close(MAIL);'
Yo could test it through the Zentyal webmail too.

Cheers!

PS: I tested it from Zentyal 6.1 and 6.2
- Do my pigeons bother you passing over your land?
- They block the sun!

G. Guareschi., Don Camillo.,

nickpiggott

  • Zen Apprentice
  • *
  • Posts: 23
  • Karma: +8/-0
    • View Profile
Re: Outgoing mail is rejected with invalid address format
« Reply #2 on: May 28, 2020, 02:02:01 pm »
Posting this so future readers can see the problem and the fix.

Samba 4.7.6 ignores the setting for "winbind use default domain" on the machine running the AD-DC.

That means all usernames are now in the format "DOMAIN\username" on the AD-DC machine - you'll also notice this logging into the Zentyal webadmin. This cannot be changed.

The fix I had to put in place:

Copy the postfix configuration stub into /etc/zentyal/stubs/mail if it doesn't already exist there.
Code: [Select]
mkdir /etc/zentyal/stubs/mail
cp /usr/share/zental/stubs/mail/main.cf.mas /etc/zentyal/stubs/mail/

Edit /etc/zentyal/stubs/mail/main.cf.mas to add this line
Code: [Select]
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
Create a file /etc/postfile/sender_canoncial with the content
Code: [Select]
# remove DOMAIN segment of DOMAIN\username sender
/([A-Z]+)\\(.*)/ $2

Restart Zentyal Mail
Code: [Select]
sudo zs mail restart
This re-writes outbound usernames as "username", stripping the DOMAIN section.

You also have to create symlinks in /mail/var. For each mailbox "username", create a hard symlink to DOMAIN\username
Code: [Select]
cd /mail/var
sudo ln  username "DOMAIN\username"
otherwise the mail command won't work for you users.