Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Add ability to set SMTP envelope addresses #6570

Closed
wants to merge 6 commits into from

Conversation

ameir
Copy link
Contributor

@ameir ameir commented Aug 13, 2014

I am working on a program that is called from a mail server, and re-injects the message back into the mail queue to be sent to multiple recipients (using a Postfix content filter). The problem is that this library forms the RCPT TO: information from the message headers, which in this case, will not work (the goal is for the message to arrive untouched). There should be an option to pass SMTP-level message options to the transport to handle situations like this.

I currently have something like the following:

$email = file_get_contents("php://stdin");
$headers = $body = '';
Zend\Mime\Decode::splitMessage($email, $headers, $body);

// Setup SMTP transport
$transport = new Zend\Mail\Transport\Smtp();
$options = new Zend\Mail\Transport\SmtpOptions(
        array(
    'name' => php_uname('n'),
    'host' => '127.0.0.1',
    'port' => 10025,
        )
);
$transport->setOptions($options);

$message = new Zend\Mail\Message();
$message->setHeaders($headers);
$message->setBody($body);
$transport->send($message);

This pull request will allow you to do:

    $message = new Zend\Mail\Message();
    $message->setHeaders($headers);
    $message->setBody($body);
    $envelope = new Zend\Mail\Transport\Envelope(array(
        'from' => '[email protected]',
        'to' => '[email protected]',
            )
    );
    $transport->setEnvelope($envelope);
    $transport->send($message);

@Ocramius
Copy link
Member

@ameir thanks for the contribution!

A couple of things are still missing though:

/**
* @var string
*/
protected $from = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null is not required in php

@ameir
Copy link
Contributor Author

ameir commented Aug 13, 2014

Thanks, @Ocramius! I'll work on some test cases and update this PR in a bit.

/**
* Get RCPT TO
*
* @return string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string|null

@Ocramius
Copy link
Member

Ocramius commented Jan 3, 2015

This PR is still requiring tests before being mergeable

@weierophinney
Copy link
Member

Ping @ameir — I'd love to merge this for 2.4, but we need tests for the new functionality. Would you be able to do that in the next 2 weeks?

@ameir
Copy link
Contributor Author

ameir commented Feb 19, 2015

@weierophinney I'll see if I can find time to knock this out in the next few days. My apologies for the delays; my schedule has been hectic. I have a number of other changes to perform PRs against as well (https://github.com/ameir/zf2/tree/mail-improvements), but they'll also need tests.

@ameir
Copy link
Contributor Author

ameir commented Feb 20, 2015

@weierophinney @Ocramius I wrote tests and updated the code accordingly. I had to reintroduce the setters and getters due to a separate test failing that checked for existence of those. I then updated the code to use the setters/getters. Let me know if this needs further modification.

@weierophinney weierophinney added this to the 2.4.0 milestone Feb 25, 2015
weierophinney added a commit that referenced this pull request Feb 25, 2015
Add ability to set SMTP envelope addresses
weierophinney added a commit that referenced this pull request Feb 25, 2015
@weierophinney
Copy link
Member

Incorporated feedback from @Ocramius and merged to develop for release with 2.4.

weierophinney added a commit to zendframework/zend-mail that referenced this pull request May 14, 2015
…nvelope

Add ability to set SMTP envelope addresses
weierophinney added a commit to zendframework/zend-mail that referenced this pull request May 14, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants