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

how to test cc with mail hog #261

Open
ellahikamran opened this issue Oct 25, 2019 · 6 comments
Open

how to test cc with mail hog #261

ellahikamran opened this issue Oct 25, 2019 · 6 comments

Comments

@ellahikamran
Copy link

Hi , can you let me know how i can test CC and BCC with mailhog or mhsendmail

@C-Duv
Copy link

C-Duv commented Mar 30, 2020

If by "test CC and BCC with mailhog" you mean being able to see, in MailHog e-mails sent with Cc: and Bcc: headers set: then yes, you can.

Sending an e-mail (using MailHog as SMTP server) with:

  • To: x@example.com
  • Cc: y@example.com
  • Bcc: z@example.com

will create 3 separate e-mails in MailHog interface.

PS: Setting the same recipient e-mail address for each header will still create 3 separate e-mails.

@stefkes
Copy link

stefkes commented Dec 3, 2020

If you download the email from Mailhog as an .eml file and open that file in a client like Thunderbird you'll clearly see the BCC & CC values. Inline images will also be visible.

@eexit
Copy link

eexit commented Dec 21, 2020

@C-Duv This is not true. I tested with this command and only one email is showing up, however, I can indeed see the headers:

mhsendmail test@mailhog.local <<EOF
From: App <app@mailhog.local>
To: Test <test@mailhog.local>
Cc: <cc@mailhog.local>
Bcc: bcc@mailhog.local
Subject: Test message

Some content!
EOF

Screenshot 2020-12-21 at 9 06 09 PM

I would like to understand what's the logic behind this: is the SMTP protocol smart enough to parse the message and send a single copy of each Bcc recipient while hiding others or should this logic be userland?

@C-Duv
Copy link

C-Duv commented Dec 21, 2020

@eexit I stand corrected then. I will check my setup then (I use both To: and Bcc:)...

And I am looking forward an explanation / pointer to the documentation / code from the maintainer. Such internal behavior explanation could profit others.

@eexit
Copy link

eexit commented Dec 28, 2020

Hello,

I've read some more documentation and compared 2 famous PHP email sending libraries (PHPMailer & SwiftMailer).
From what I understood:

Some clients merge all recipients and trigger one transaction while others do one transaction for To+Cc and one transaction for each Bcc.

So, to test Cc, you should only add your Cc and your SMTP client should include this header, while for the Bcc, it depends on your SMTP client: if it merges all recipients (To, Cc, Bcc), then you can't check from the UI this information. If the Bcc recipients are sent individually, then you'll see extra instances of your email.

In any cases, check the MH logs. Here's an example with PHPMailer:

$mailer = new \PHPMailer();

$mailer->isSMTP();
$mailer->Port = 1025;
$mailer->Host = '127.0.0.1';
$mailer->setFrom('test@example.com');
$mailer->addAddress('recipient@example.com');
$mailer->addCC('copy@example.com');
$mailer->addBCC('hidden@example.com');
$mailer->Subject = 'Test Email';
$mailer->Body = 'Test email content';

$mailer->send();
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Starting session
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: INVALID] Started session, switching to ESTABLISH state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 35 bytes: '220 mailhog.example ESMTP MailHog\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 19 bytes: 'EHLO local-docker\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: ESTABLISH] Processing line: EHLO local-docker
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: ESTABLISH] In state 1, got command 'EHLO', args 'local-docker'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: ESTABLISH] In ESTABLISH state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: ESTABLISH] Got EHLO command, switching to MAIL state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 24 bytes: '250-Hello local-docker\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 16 bytes: '250-PIPELINING\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 16 bytes: '250 AUTH PLAIN\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 30 bytes: 'MAIL FROM:<test@example.com>\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: MAIL] Processing line: MAIL FROM:<test@example.com>
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: MAIL] In state 6, got command 'MAIL', args 'FROM:<test@example.com>'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: MAIL] In MAIL state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: MAIL] Got MAIL command, switching to RCPT state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 32 bytes: '250 Sender test@example.com ok\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 33 bytes: 'RCPT TO:<recipient@example.com>\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Processing line: RCPT TO:<recipient@example.com>
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In state 7, got command 'RCPT', args 'TO:<recipient@example.com>'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In RCPT state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Got RCPT command
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 40 bytes: '250 Recipient recipient@example.com ok\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 28 bytes: 'RCPT TO:<copy@example.com>\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Processing line: RCPT TO:<copy@example.com>
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In state 7, got command 'RCPT', args 'TO:<copy@example.com>'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In RCPT state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Got RCPT command
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 35 bytes: '250 Recipient copy@example.com ok\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 30 bytes: 'RCPT TO:<hidden@example.com>\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Processing line: RCPT TO:<hidden@example.com>
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In state 7, got command 'RCPT', args 'TO:<hidden@example.com>'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In RCPT state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Got RCPT command
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 37 bytes: '250 Recipient hidden@example.com ok\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 6 bytes: 'DATA\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Processing line: DATA
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In state 7, got command 'DATA', args ''
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] In RCPT state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: RCPT] Got DATA command, switching to DATA state
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Sent 37 bytes: '354 End data with <CR><LF>.<CR><LF>\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 39 bytes: 'Date: Mon, 28 Dec 2020 12:39:07 +0000\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] Received 316 bytes: 'To: recipient@example.com\r\nFrom: test@example.com\r\nCc: copy@example.com\r\nSubject: Test Email\r\nMessage-ID: <a3bd40cc18d75ee023acc59256887394@local-docker>\r\nX-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=iso-8859-1\r\n\r\nTest email content\r\n\r\n.\r\n'
2020/12/28 12:39:07 [SMTP 172.19.0.16:41734] [PROTO: DATA] Got EOF, storing message and switching to MAIL state

@g13013
Copy link

g13013 commented Dec 28, 2020

for what it's worth, BCC should never appear in the headers, but they are transmitted the email by including them in the RCPT TO commands issued to smtp relays/servers

You must differentiate between what the mail client sees and what the smtp server in charge of delivery receives to transmit the email. the email DATA contain the final messages to be sent to all recipients, so including the the BCC header doesn't make any sense, since it is intended to be invisible to To, CC and other BCC recipients, keep in mind that the relay smtp is not interested in the headers in général, unless in some cases where they are read by some security and anti-spam systems.

So consider this:
from: header + MAIL FROM command
to: header + RCPT TO command
cc: header + RCPT TO command
bcc: header + RCPT TO command

So, I don't know for MailHog, but assuming there is 1 address in each header TO, CC, BCC 3 identical emails would be sent to each of the addresses without any mention of the BCC address.

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

No branches or pull requests

5 participants