Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Sparkpost bcc #13237

Merged
merged 5 commits into from
Apr 25, 2016
Merged

[5.2] Sparkpost bcc #13237

merged 5 commits into from
Apr 25, 2016

Conversation

pochocho
Copy link
Contributor

I found that when sending to multiple email addresses would result to all addresses displaying in the "to" field of the email. This did not happen with Mandrill. After reading the SparkPost Docs, the use of the BCC field is the only way to hide email addresses, but the current implementation would not allow to set the "header_to" option on the recipients because of the usage of the "email_rfc822" for the content. This is my first contribution so I understand my code might not be the best so bear with me, any suggestions/comments appreciated.

@GrahamCampbell GrahamCampbell changed the title Sparkpostbcc [5.2] Sparkpostbcc Apr 20, 2016
@GrahamCampbell GrahamCampbell changed the title [5.2] Sparkpostbcc [5.2] Sparkpost bcc Apr 20, 2016
@BrandonSurowiec
Copy link
Contributor

In the _getFrom()_ method, Instead of doing:

return ['name' => $name, 'email' => $email];

You could do:

return compact('name', 'email');

@jbrooksuk
Copy link
Member

@BrandonSurowiec is there any need for that? Just passing the array itself is more verbose, no?

@BrandonSurowiec
Copy link
Contributor

@jbrooksuk It's cleaner and easier to read IMO since it gets rid of the duplication. Taylor uses it throughout the Laravel source.

@pochocho
Copy link
Contributor Author

@jbrooksuk I agree with @BrandonSurowiec, its more consistent with the framework

@billmn
Copy link
Contributor

billmn commented May 27, 2016

@pochocho I'm working on a fix for Sparkpost's driver. Which mail client have you used to find the BCC issue?

I've tried this code with "email_rfc822" (billmn@e2d0378) and using OS X Mail and Gmail ... all seems ok.

Can you give me a feedback?

@pochocho
Copy link
Contributor Author

@billmn I saw the issue on thunderbird. Also the issue happens when sending to multiple recipients at once.

It gets fixed with my solution that was merged, by assigning an individual header for each BCC recipient.

@billmn
Copy link
Contributor

billmn commented May 27, 2016

My code restore the use of "email_rfc822" To simplify the driver and fix some issues.

After some tests I haven't found the BCC issue.

@pochocho
Copy link
Contributor Author

@billmn are you sending to multiple recipients? when using multiple I had 2 scenarios if I sent the array as the "to" option, evryone could access the recipients addresses. If done through BCC, the email client wouldn't show a "to" field.

How are you calling the mail function? just to check if it has to do on how I'm doing it.

@billmn
Copy link
Contributor

billmn commented May 27, 2016

Yes, I have used this code and all seems work. No BCC's addresses in the TO field.

Mail::send('test', [], function($message) {
    $message
        ->to([
            'address1@mail.dev',
            'address2@mail.dev',
        ])
        ->bcc([
            'address3@mail.dev',
            'address4@mail.dev',
        ])
        ->subject('Test from SparkPost')
        ->attach(public_path('robots.txt'));
});

@pochocho
Copy link
Contributor Author

I tried your code and got the same results. the problem is not that BCC fields show. its the fact that no address appears in the "to" field.

on the email yo see something like:

From: noreply@domain.com
Subject: a subject
to:

Tested on Gmail and Thunderbird, both with the same results.

I'm using mail function as follows:

Mail::send('test', [], function($message) {
    $message
        ->bcc([
            'address3@mail.dev',
            'address4@mail.dev',
        ])
        ->subject('Test from SparkPost')
        ->attach(public_path('robots.txt'));
});

@billmn
Copy link
Contributor

billmn commented May 27, 2016

Is absolutely normal that TO field is empty if you specify addresses only in BCC field.

@pochocho
Copy link
Contributor Author

Yes but the issue I opened is because when using mandrill you could send an email to mass recipients all in the "to" field and the full list of recipients would not be made public. The only work around is to send them trough BCC but email recipients should be able to see the email address that the email was sent to.

using 'email_rfc822' overwirtes any headers set to recipients. Which I set in the following section of the code in the getRecepients function:

$recipients = array_map(function ($address) {
            return ['address' => [ 'email' => $address ,'header_to' => $address] ];
        }, $to);

This is also specified in the sparkpost api docs

@billmn
Copy link
Contributor

billmn commented May 28, 2016

@pochocho I did some tests using:

Mail::send('test', [], function($message) {
    $message
        ->bcc([
            'address3@mail.dev',
            'address4@mail.dev',
        ])
        ->subject('Test from SparkPost')
        ->attach(public_path('robots.txt'));
});

and no address appears in the "TO" field also with SMTP and Mailgun driver.
Have you tried with this 2 drivers?

@pochocho
Copy link
Contributor Author

@billmn havent tried those to drivers. Strange that the attachments wont work without rfc_822 I can look into it next week if you havent figured it out. Im away this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants