[ZendTo] RFC5321.MailFrom address in notification emails

Mike Brudenell mike.brudenell at york.ac.uk
Thu Jun 22 18:30:20 BST 2017


Hi, Jules!

Yes, we did indeed use MailScanner for quite a few years, I think stopping
when we changed from Sendmail to Exim (circa 2007), and definitely when we
moved to using G Suite. You hav a good memory! :-)

Looking at the ChangeLog for our ZendTo we're running 4.20-6 so don't have
the PHPMailer stuff in our installation at present. We should probably see
about updating over our summer vacation period when the students are away.

So I'm only able to look only at the PHPMailer documentation and source
code itself, without the context of being in the ZendTo source or the joy
of knowing PHP…

It looks like you need to set the "Sender" attribute to the address you
want to use in the RFC5321.MailFrom, but I can't see a function to do that.
Instead I can only see *setFrom()* which takes a third Boolean argument. If
this is true and Sender is still empty then Sender gets set to the email
address supplied for the From.

So, fabricating some sort of horrible fictitious pseudocode, maybe
something like this…

if ($personUploadingIsLoggedIn &&
    $personUploadingEmailAddress <matches your internal domains
pattern/list>) {
        $mail->setFrom($personUploadingEmailAddress);
    } else {
        $mail->setFrom($envelopeSenderAddress);
    }
$mail->setFrom(...arguments as you have now to set the RFC5322.From...);

where

   - $personUploadingIsLoggedIn is a variable or test saying whether the
   person performing the upload is logged in (true) or doing their upload
   without logging in (false)

   - $personUploadingEmailAddress is the email address and textual name of
   the logged in person doing the upload (which you clearly have somewhere as
   it's shown in the *Your email address* area of the *Information about
   the Sender* page when a logged in user is preparing their upload, and
   presumably trust it as it's obtained from the logged in user's directory
   details and is used elsewhere)

   - $envelopeSenderAddress is a new preference setting where you can set
   the RFC5321.MailFrom address to be used as the sender address in the SMTP
   envelope. (Or else extract the address field from the variable holding
   the EmailSenderAddress preference, although this might be fiddly.)

   - $serviceTitle is the variable holding the ServiceTitle preference's
   value.

If I've got this right then the first call to $mail->setFrom() sets:

   - the RFC5322.From details to either $personUploadingEmailAddress and an
   empty descriptive name, or to $envelopeSenderAddress and an empty
   descriptive name (these are stored in the From and FromName attributes of
   the message object)

   - the RFC5321.MailFrom to either $personUploadingEmailAddress, or
   to $envelopeSenderAddress (this is stored in the Sender attribute of the
   message object)

Then the second call to $mail->setFrom() sets the RFC5322.From details to
whatever you supply here (use the values as you are right now), and
*doesn't* change the RFC5321.MailFrom address as that's no longer empty.

(The code in class.phpmailer.php in the setMail function tests whether the
third parameter is set, or has defaulted to true *and* the Sender value is
empty before changing it. So by setting Sender using the first call it
shouldn't get changed by the second call.)

Hopefully this will let you set the RFC5321.MailFrom to the address
Non-Delivery Reports should go to, and the RFC5322.From as you're doing
right now. (If it doesn't, try setting the third argument of the second
call to setMail() to false, which will force it not to alter the already
set value of Sender.)

It does rely on you having a trustworthy email address for a user who has
logged into the service though.

Sorry if that's very wooly: trying to fathom the PHP code and the time of
day is making my brain hurt and tryping desentigrat. :-)

Cheese,
Mike B-)


On 22 June 2017 at 17:11, Jules <Jules at zend.to> wrote:

> Mike,
>
> Long time no talk. Didn't you folks used to run MailScanner? :-)
>
> The new code only uses PHP's mail() if the SMTP settings are not set in
> preferences.php.
> If they are set at all, it now uses PHPmailer instead.
>     https://github.com/PHPMailer/PHPMailer
>
> On the basis that PHPMailer can do many more clever things, do you fancy
> having a read of the docs there and suggesting an improvement that I could
> make when using PHPMailer?
>
> Thanks!
> Jules.
>

-- 
Systems Administrator & Change Manager
IT Services, University of York, Heslington, York YO10 5DD, UK
Tel: +44-(0)1904-323811

Web: www.york.ac.uk/it-services
Disclaimer: www.york.ac.uk/docs/disclaimer/email.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/zendto/attachments/20170622/9c8d1ef4/attachment.html 


More information about the ZendTo mailing list