# SMTP Code examples
# Python
# Java
# PHP
The SMTP code depends on the mail sending module. First, you need to install pear.
Pear installation steps:
Download installation package : curl -o go-pear.php http://pear.php.net/go-pear.phar
Install: php go-pear.php
Install the dependency library through pear
pear install Mail
pear install Mail_Mime
pear install Net_SMTP
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
PHP example Fast sending, no need to get messageId.
PHP example2 Need to get messageId.
1. In the Lib Library of PHP, find the mail / smtp.php file.
2. Modify the return value of the 329 line 'send' function. Change 'return true' to 'return $args'.
Next, you can call the following code to send the mail and get the messageId.
1
2
3
2
3
# Ruby
The code needs to install rest client
gem install 'rest-client'
1
Ruby exampleFast sending, no need to get messageId.
Ruby example2Need to get messageId.
The sending of SMTP depends on the net / smtp.rb module, because the module does not return the information of the server by default when the sending is successful.
Therefore, if you need to get the messageId returned by the server, you need to do the following.
First, find the net / smtp.rb file in your ruby lib library, and add a return value to the 915 line data function. The operation is as follows:
Check_respones res
res
return res.message
1
2
3
2
3
Then on line 660, send_ messages function and modify it as follows .
def send_message(msgstr, from_addr, *to_addrs)
raise IOError, 'closed session' unless @socket
response = ""
mailfrom from_addr
rcptto_list(to addrs) {response = data msgstr}
return response
end
1
2
3
4
5
6
7
2
3
4
5
6
7