[TASK] Sending an Email with ESMTP Protocol

[TASK] Sending an Email with ESMTP Protocol

Postby admin » Tue Oct 17, 2017 10:28 am

We will go through an example of sending an Email by PHPoC Blue or Black.

There are two popular protocols to send Email: SMTP and ESMTP.
PHPoC supports libraries for both prototol. Depending on your mail server, you might use SMTP or ESMTP protocol. For example, Gmail uses ESMTP, so, to send email from a Gmail account, you need to use ESMTP library.

This example is a simple course uses the ESMTP library to send email from Gmail.
For sending email using SMTP protocol, refer to this example

Source Codes
1. task0.php
Code: Select all

<?php

if(_SERVER("REQUEST_METHOD"))
    exit; 
// avoid php execution via http request

include_once "/lib/sn_dns.php";
include_once 
"/lib/sn_esmtp.php";

echo 
"PHPoC example : send email via out-going mail server\r\n";

//esmtp_setup(udp_id, tcp_id, "x.x.x.x");
//esmtp_hostname("from_domain.com");
esmtp_account("from_id@from_domain.com""from_name");
esmtp_auth("msa_id""msa_password");
esmtp_msa("smtp.gmail.com"465);
//esmtp_msa("smtp.naver.com", 465);
//esmtp_msa("smtp.daum.net", 465);

$subject "msa test";
$message "Hi PHPoC\r\nThis is PHPoC msa test email\r\nGood bye\r\n";

$msg esmtp_send("to_id@to_domain.com""to_name"$subject$message);

if(
$msg == "221")
    echo 
"send mail successful\r\n";
else
    echo 
"send mail failed\r\n";

?>


How to use

1. Make sure that your PHPoC Blue or Black is connected to the Internet.

2. Please download a PSP (PHPoC Support Package) of libraries and examples from PHPoC.

3. Connect PHPoC Blue or Black to your PC via USB cable.

4. Run PHPoC Debugger.

5. Upload all libraries in PSP to your PHPoC Blue or Black through PHPoC Debugger.
In fact, you only need to upload sn_dns.php and sn_esmtp.php files to use in this example. But for future use, you can upload all.
※ Note that: the libraries should be located in the /lib folder.
psp_email_eg_02.png
psp_email_eg_02.png (8.84 KiB) Viewed 54 times


6. Find an example of email_msa in the PSP.
psp_email_estmp_1.JPG
psp_email_estmp_1.JPG (14.29 KiB) Viewed 54 times


7. Upload init.php and task0.php files to your PHPoC Blue or Black.
※ Note that: the init.php and task0.php files should be located in the root folder.
psp_email_eg_04.png
psp_email_eg_04.png (2.22 KiB) Viewed 54 times


8. Modify the e-mail address and name to yours in task0.php file. For example, your email address is example@gmail.com and password is example_password
psp_email_estmp_modified.JPG
psp_email_estmp_modified.JPG (67.43 KiB) Viewed 54 times


9. Create phpoc.ini file with content as follows: ssl0_rxbuf_size = 4096
psp_email_estmp_ini.JPG
psp_email_estmp_ini.JPG (18.82 KiB) Viewed 54 times


10. Upload the task0.php to your PHPoC Blue or Black again.

11. Run the example.
psp_email_estmp_result.JPG
psp_email_estmp_result.JPG (25.52 KiB) Viewed 54 times


※ Note that: Google may block sign-in attempts from some apps or devices that do not use modern security standards. Change your settings to allow less secure apps to access your account: https://www.google.com/settings/security/lesssecureapps
admin
Site Admin
 
Posts: 166
Joined: Mon Jan 20, 2014 4:40 pm

Return to Example

Who is online

Users browsing this forum: No registered users and 1 guest