ruby 发送post请求_使用Ruby发送电子邮件
ruby 發送post請求
Ruby發送電子郵件 (Ruby sending email)
Sending emails and routing email among mail servers are handled by Simple Mail Transfer Protocol commonly known as SMTP. Net::SMTP class is a predefined class in Ruby’s library which is purposefully defined for Simple Mail Transfer Protocol.
在郵件服務器之間發送電子郵件和路由電子郵件由通常稱為SMTP的 簡單郵件傳輸協議處理。 Net :: SMTP類是Ruby庫中的預定義類,它是為簡單郵件傳輸協議專門定義的。
Net::SMTP has two methods namely new and start. The parameter specification goes as follows,
Net :: SMTP有兩種方法,即new和start。 參數規格如下:
新: (new:)
It consumes two parameters, the first one is a server which is by default 'localhost' and the port number which is by default 25.
它使用兩個參數,第一個是默認為“ localhost”的服務器,默認為25的端口號。
開始: (start:)
It consumes six parameters namely server, port, domain, account, password, and authtype. The default value of server is localhost, the port is 25, the domain is ENV["HOSTNAME"], account and password is nil and authtype is cram_md5.
它使用六個參數,即服務器,端口,域,帳戶,密碼和身份驗證類型。 服務器的默認值為localhost,端口為25,域為ENV [“ HOSTNAME”],帳戶和密碼為nil,身份驗證類型為cram_md5。
sendmail is a method of an SMTP object which takes three parameters namely The source, The sender and the recipient.
sendmail是SMTP對象的一種方法,它采用三個參數,即源,發件人和收件人。
Now, let us understand a very simple way to send one email using Ruby code. refer the example given below,
現在,讓我們了解一種使用Ruby代碼發送一封電子郵件的非常簡單的方法。 請參考下面的示例,
require 'net/smtp'message = <<MESSAGE_END From: Includehelp <[email?protected]> To: Hrithik sinha <[email?protected]> Subject: Urgent InformationHello there, Greeting from Includehelp. We hope, you are doing good. Have a great day. Read articles at Includhelp for best programming guidance. MESSAGE_ENDNet::SMTP.start('localhost') do |smtp|smtp.send_message message, '[email?protected]', '[email?protected]' endThe code given above is a very basic way to send email using Ruby. We have integrated a very simple email message. It is required to take care of the format of headers properly. We all know that an email requires three things namely a From, To and Subject which should be identical from the body of an email with the help of a blank line.
上面給出的代碼是使用Ruby發送電子郵件的一種非常基本的方法。 我們已經集成了非常簡單的電子郵件。 需要正確處理標題格式。 我們都知道,電子郵件需要三項內容,即“發件人”,“收件人”和“主題”,在空白行的幫助下,它們應與電子郵件正文相同。
For sending an email, we are supposed to use Net::SMTP class which allows us to connect with the SMTP server on our machine and then make use of send_message method with the message specified, the sender’s address and the receiver’s address as parameters.
為了發送電子郵件,我們應該使用Net :: SMTP類,該類允許我們與計算機上的SMTP服務器連接,然后使用send_message方法,并將指定的消息,發送者的地址和接收者的地址作為參數。
If you want to send an HTML file using Ruby script, that file will be treated as a normal document even after including HTML tags in the documents. Net::SMTP class provides you a feature to send an HTML message with the help of an email. Refer the following code for instance.
如果要使用Ruby腳本發送HTML文件,即使在文檔中包含HTML標記后,該文件也將被視為普通文檔。 Net :: SMTP類為您提供了借助電子郵件發送HTML消息的功能。 例如,請參考以下代碼。
require 'net/smtp'message = <<MESSAGE_END From: Hrihik Sinha <[email?protected]> To: Saksham Sharma <[email?protected]> MIME-Version: 1.0 Content-type: text/html Subject: An exemplary emailhey bro,
嘿哥們兒,
This is an example. Read articles at Includehelp.com for better understanding of concepts.
這是一個例子。 閱讀Includehelp.com上的文章,以更好地理解概念。
<h1>Write heading here</h1> <p>This is a paragraph</p> <hr> MESSAGE_ENDNet::SMTP.start('localhost') do |smtp|smtp.send_message message, '[email?protected]', '[email?protected]' endYou are supposed to specify Mime version, the type of content and character set if you want to email an HTML text using Ruby script.
如果要使用Ruby腳本通過電子郵件發送HTML文本,則應指定Mime版本,內容類型和字符集。
翻譯自: https://www.includehelp.com/ruby/sending-email-using-ruby.aspx
ruby 發送post請求
總結
以上是生活随笔為你收集整理的ruby 发送post请求_使用Ruby发送电子邮件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gif 格式 完整 检查_GIF的完整格
- 下一篇: electron 菜单栏_如何在Elec