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 Information
Hello there, Greeting from Includehelp.
We hope, you are doing good. Have a great day.
Read articles at Includhelp for best programming guidance.
MESSAGE_END
Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, '[email protected]', '[email protected]'
end

The 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 email

hey 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_END
Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, '[email protected]', '[email protected]'
end

You 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请求

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543824.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Centos Git1.7.1升级到Git2.2.1

Centos Git1.7.1升级到Git2.2.1安装需求&#xff1a;># yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc ># yum install asciidoc xmlto -y ># yum install gcc perl-ExtUtils-MakeMaker error: /utf8.c:463: undefined r…

tgc 什么意思 tgt_TGT的完整形式是什么?

tgc 什么意思 tgtTGT&#xff1a;训练有素的研究生老师 (TGT: Trained Graduate Teacher) TGT is an abbreviation of Trained Graduate Teacher. It is a title, not a teaching program that is given to a graduate person who has done completion of training in teaching…

svn的使用(Mac)

2019独角兽企业重金招聘Python工程师标准>>> 从服务器下载代码 在终端中输入svn checkout svn://localhost/mycode --username用户名 --password密码 /Users/apple/Documents/code指令意思&#xff1a;将服务器中mycode仓库的内容下载到/Users/apple/Documents/myCo…

scala语言示例_标有示例的Scala关键字

scala语言示例Scala | 任一关键字 (Scala | Either Keyword) Either is a container similar to the option which has two values, they are referred to as children. The left and right children are named as the right child and left child. 这是一个类似于选项的容器&a…

css 中文文字字体_使用CSS的网络字体

css 中文文字字体CSS | 网络字体 (CSS | Web fonts) Web fonts allow people to use fonts that are not pre-installed in their computers. When you want to include a particular font simply include the font file on your browser and it will be downloaded. Web字体允…

Ajax实践之用户是否存在

关于Ajax在之前的学习中&#xff0c;已经对它的基础知识有了初步的了解。仅仅是欠实践。那么接下来就让实践来检验一下真理吧&#xff01; 基础见&#xff1a;http://blog.csdn.net/liu_yujie2011com/article/details/29812777 那么先回忆一下&#xff0c;Ajax是用来解决什么问…

vb 导出整数 科学计数法_可整数组的计数

vb 导出整数 科学计数法Problem statement: 问题陈述&#xff1a; Given two positive integer n and m, find how many arrays of size n that can be formed such that: 给定两个正整数n和m &#xff0c;找出可以形成多少个大小为n的数组&#xff1a; Each element of the …

C4.5决策树算法概念学习

数据挖掘一般是指从大量的数据中自动搜索隐藏于其中的有着特殊关系性的信息的过程。 •分类和聚类•分类(Classification)就是按照某种标准给对象贴标签&#xff0c;再根据标签来区分归类&#xff0c;类别数不变。•聚类(clustering)是指根据“物以类聚”的原理&#xff0c;将本…

python修改y轴刻度_Python | Y轴刻度限制

python修改y轴刻度In some cases, we need to visualize our data within some defined range rather than the whole data. For this, we generally set the y-axis scale within a limit and this ultimately helps us to visualize better. Sometimes, it acts as zooming a…

em算法示例_带有示例HTML'em'标签

em算法示例<em>标签 (<em> Tag) <em> tag in HTML is used to display the text in emphasized form. <em> tag add semantic meaning to the text, text inside it is treated as emphasized text. HTML中的<em>标记用于以强调形式显示文本。 &…

联合使用 HTML 5、地理定位 API

查找并跟踪位置坐标以用在各种 Web 服务中 在这个由五个部分所组成的系列的第一部分中&#xff0c;您将接触到移动 Web 应用程序中最流行的新技术&#xff1a;地理定位。高端智能手机都内置 GPS&#xff0c;现在您将了解 Web 服务如何使用它。在本文中&#xff0c;您将学到如何…

list下界_下界理论

list下界下界理论 (Lower Bound Theory) Lower bound (L(n)) is a property of the specific problem i.e. the sorting problem, matrix multiplication not of any particular algorithm solving that problem. 下界(L(n))是特定问题(即排序问题)的矩阵&#xff0c;不是解决该…

Mac OSX 安装nvm(node.js版本管理器)

我的系统 1.打开github官网https://github.com/&#xff0c;输入nvm搜索,选择creationix&#xff0f;nvm&#xff0c;打开 2.找到Install script&#xff0c;复制 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash . 3. 打开终端&#xf…

HTML中的类属性

The class attribute in HTML is used to specify or set a single or multiple class names to an element for an HTML and XHTML elements. Its majorly used to indicate a class in a style sheet. HTML中的class属性用于为HTML和XHTML元素指定或设置一个元素名称或多个类…

关于HTML5标签不兼容(IE6~8)

HTML5的语义化标签以及属性&#xff0c;可以让开发者非常方便地实现清晰的web页面布局&#xff0c;加上CSS3的效果渲染&#xff0c;快速建立丰富灵活的web页面显得非常简单。 比较常用的HTML5的新标签元素有&#xff1a; <header>定义页面或区段的头部&#xff1b;<na…

zzz,zzz,zz9_ZZZ的完整形式是什么?

zzz,zzz,zz9ZZZ&#xff1a;睡觉&#xff0c;无聊&#xff0c;累 (ZZZ: Sleeping, Bored, Tired) ZZZ is an abbreviation of "Sleeping, Bored, Tired". ZZZ是“睡觉&#xff0c;无聊&#xff0c;累了”的缩写 。 It is an expression, which is commonly used in …

uboot启动 及命令分析(3)

u-boot命令 先贴一个重要结构,位于uboot/include/command.h,这个结构代表每个uboot命令 struct cmd_tbl_s { char *name; /* Command Name */ int maxargs; /* maximum number of arguments*/ int repeatable;/* autorepeat allowed? */ /* Implem…

Mozilla开源了VR框架A-Frame

Mozilla创建并开源了A-Frame&#xff0c;这是一个用于在桌面浏览器、智能手机和Oculus Rift上创建VR场景的框架。\\A-Frame是一个在浏览器中创建VR体验的开源框架。该框架由Mozilla的MozVR团队创建和开发。A-Frame使用了一个在游戏开发中经常使用的“实体-组件&#xff08;Enti…

css网格_CSS网格容器

css网格CSS | 网格容器 (CSS | Grid Containers) There are numerous ways to display our list items or elements. For instance, we can display them in the navigation bar, in a menu bar and whatnot. Well, it would be right to say that there are many more such me…

c ++向量库_在C ++中对2D向量进行排序

c 向量库As per as a 2D vector is concerned its a vector of a 1D vector. But what we do in sorting a 1D vector like, 就2D向量而言&#xff0c;它是1D向量的向量 。 但是我们在对一维向量进行排序时所做的工作 sort(vector.begin(),vector.end());We cant do the same …