6.40. Ruby send email-SMTP

发布时间 :2023-11-01 23:00:07 UTC      

SMTP (Simple Mail Transfer Protocol), or simple Mail transfer Protocol, is aset of rules for sending messages from source to destination, which controls the way letters are transferred.

Ruby provides Net::SMTP to send emails and provides two methods, new and start :

new method has two parameters:

  • server name default is localhost

  • port number default is 25

The start method has the following parameters:

  • server - SMTP server IP, default is localhost

  • port -port number, default is 25

  • domain -domain name of the sender of the mail. Default is ENV["HOSTNAME"]

  • account -user name, default nil

  • password -user password. Default is nil

  • authtype -validation type, default is cram_md5

The SMTP object instantiation method calls the sendmail parameters are as follows:

  • source -anything returned by a string or array or by each iterator at any time.

  • sender -A string that appears in the email form field

  • recipients -A string or array of strings that represents the address of the recipient.

6.40.1. Example #

The following provides a simple Ruby script to send messages:

Example #

require'net/smtp'message=
<<MESSAGE_ENDFrom:PrivatePerson<me@fromdomain.com>To:ATestUser
<test@todomain.com>Subject:SMTPe-mailtestThisisateste-mailmessage.MESSAGE_ENDNet::SMTP.
start('localhost')do\|smtp\|smtp.send_messagemessage,'me@fromdomain.com','test@todomain.com'end

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.