Email headers in log

Ruslan Migory

New Member
Hello. I would like to see email headers and content of email that i send when i click Test template button. Probably there is a possibility to add some code to see it in application logs?
The idea is to see a full version of email with headers and everything exactly how it sends to recipient.
 
Here it is a chunk of headers from mailtester:
Received: by mail-tester.com (Postfix, from userid 500)
id 2F0859FCFC; Mon, 27 Jan 2020 14:55:27 +0100 (CET)
Authentication-Results: mail-tester.com;
dkim=pass (2048-bit key; unprotected) header.d=fdde.trade header.i=@fdde.trade header.b=Nd9M6Y0I;
dkim-atps=neutral
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail-tester.com
X-Spam-Level:
X-Spam-Status: No/-0.2/5.0
X-Spam-Test-Scores: DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,
DKIM_VALID_EF=-0.1,HTML_MESSAGE=0.001,SPF_HELO_PASS=-0.001,
SPF_PASS=-0.001,URIBL_BLOCKED=0.001
X-Spam-Last-External-IP: 178.62.101.242
X-Spam-Last-External-HELO: box.fdde.trade
X-Spam-Last-External-rDNS: box.fdde.trade
X-Spam-Date-of-Scan: Mon, 27 Jan 2020 14:55:27 +0100
------------------------------
These headers were added by mailtester am i wrong?
 
Sure thing, i can do that :)
There is a hook which gets triggered each time when an email goes out, you can use it to get the full source of the email and log it.
That being said, if you create a file called init-custom.php in /apps/ folder, with this content:
PHP:
<?php 

Yii::app()->hooks->addAction('delivery_server_after_send_email', function($params, $server, $sent) {
     Yii::log($this->getMailer()->getEmailMessage($params), CLogger::LEVEL_ERROR);
});
Please beware this will log all emails that go out from the system, when you are done with your tests, delete the file.
You can see the logs in backend > misc > application log.
 
Back
Top