The default behave of Drupal is to set site-mail as "from address" if none is passed as parameter in drupal_mail. A mail server might be configured to not allow a authentication user to use another "from address". In this case, an email will be sent only if another module change the "from address", e.g. webform.

Since phpmailer enable to set an SMTP authentication user, it also should allow to set the default "from address" as the authentication user, or maybe any other than site-mail.

A workaround solution is set site-mail as the authentication user, but site-mail is an info related to the site itself not SMTP authentication. As site-mail should receive emails, a dumb "no-reply" SMTP user could not be used here.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moskito’s picture

After further investigation, I found out that to reproduce this issue a postfix server must has smtpd_sender_restrictions with reject_sender_login_mismatch[1].

That configuration actually does the mail server to check if $message['headers']['Sender'] address is owned by smtp_username.

In drupal_mail is stated

    // To prevent e-mail from looking like spam, the addresses in the Sender and
    // Return-Path headers should have a domain authorized to use the originating
    // SMTP server.
    $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from;

Drupal core suppose that site_mail address has a domain authorized. But, once phpmailer enable one to set an another SMTP server and SMTP username, the address must also be owned by SMTP username (if SMTP server configured in that way).

In this patch, there is another text area in the advanced section in configuration form called "From address". This information if filled will replace $message['headers']['Sender'] and $message['from'].
Note that making header-Sender and body-from the same avoid identity forgery. And some SMTP servers do it automatically using filters before sending the message.

[1] http://www.postfix.org/postconf.5.html#smtpd_sender_restrictions

moskito’s picture

Status: Active » Needs review
moskito’s picture

Resending patch to testbot it after #1719434: PHPMailer doesn't pass in testbot.

ayalon’s picture

Tested and Working.

Please commit this long standing issue...

moskito’s picture

Status: Needs review » Reviewed & tested by the community

I've been using it in production since my last post without problem, and ayalon has tested it. I guess it is pretty safe to set it as reviewed.

sun’s picture

I'm not sure whether I agree with this change.

Why wouldn't you set the site e-mail to the From address that you're using for e-mail communication? (Even more so, if your SMTP server requires you to use that e-mail?)

moskito’s picture

Besides it will be semantic wrong, the 'contact' core module create a site contact form which uses site mail as recipient. Probably, there are other modules that use site mail as it semantically suggests.

RavinderChopra’s picture

Issue summary: View changes

Steps to Resolve this issue. 

1. Go to Modules page 

2. Go to Webform under module page and click on configure link.

3. Go down and change the email address listed here. This is your default email address for your webform.

4. Save the form and your email address has been updated. 

Enjoy