6.40. Ruby send email-SMTP

发布时间 : 2025-10-25 13:34:05 UTC      

Page Views: 9 views

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 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。