Testing and debugging code that sends emails could be a pain; when an email is not received correctly, the source of the problem could be the network configuration, the provider, the client software, and so on.
To help you in this case, we added the ability to dump email in a local file instead of sending it. With this feature, you just need to modify the resulting file slighlty to create an EML file that can display the results in MS Outlook. You can also include email files in unit-testing procedures.
You can run the local code:
$err:=SMTP_SetPrefs(0;15;0)
$err:=SMTP_Charset(1;1)
$hostName:="file:C:\\Users\\MyWinUser\\Desktop\\test.txt"
$msgTo:="mail.to@gmail.com"
$msgFrom:="mail.sender@gmail.com"
$mailSubject:="テストメール(v17 4372) "
$mailBody:="日本語で終わる"
$err:=SMTP_QuickSend($hostName;$msgFrom;$msgTo;$mailSubject;$mailBody;0;0;$msgFrom;"password")
This produces the following .txt file:
<mail.sender@gmail.com>
<mail.to@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Date: Fri, 08 Jul 2016 16:45:24 +0200
To: mail.to@gmail.com
From: mail.sender@gmail.com
Subject: =?utf-8?B?44OG44K544OI44Oh44O844Or77yIdjE3IDQzNzIpIA==?=
=E6=97=A5=E6=9C=AC=E8=AA=9E=E3=81=A7=E7=B5=82=E3=82=8F=E3=82=8B
If you want to open this file as a standard MS Outlook email:
- Delete all lines before "Mime-Version: 1.0":
Mime-Version: 1.0
Content-Type: text/plain;charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Date: Fri, 08 Jul 2016 16:45:24 +0200
To: mail.to@gmail.com
From: mail.sender@gmail.com
Subject: =?utf-8?B?44OG44K544OI44Oh44O844Or77yIdjE3IDQzNzIpIA==?=
=E6=97=A5=E6=9C=AC=E8=AA=9E=E3=81=A7=E7=B5=82=E3=82=8F=E3=82=8B
- Save this file with the ".eml" extension, for example "test.eml".
- Double-click the file and you will see the email in MS Outlook just as if you received it from your mail server.
To comply with unit-testing mechanisms, when using with an output file, the Date header is always the following string:
Date: Fri, 08 Jul 2016 16:45:24 +0200
In this case, date comparisons will not fail in unit tests.
Note: When you use a real host (such as smtp.gmail.com), the date header gets replaced by an actual timestamp.
If you want to have an actual timestamp in your test file, you can use this feature with . In this case, you can use the command and then provide an actual Date header with .