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

ruby 发送post请求_使用Ruby发送电子邮件相关推荐

  1. jquery发送put请求_通过 Ajax 发送 PUT、DELETE 请求的两种实现方式

    一.普通请求方法发送 PUT 请求 1. 如果不用 ajax 发送 PUT,我们可以通过设置一个隐藏域设置 _method 的值,如下: 2. 控制层: @RequestMapping(value=& ...

  2. $.ajax 发送请求,JavaScript之Ajax-2 Ajax(使用Ajax发送get请求、使用Ajax发送post请求)

    一.使用Ajax发送get请求 发送异步请求的步骤 - 获取Ajax对象:获取 XMLHttpRequest对象实例 - 创建请求:调用XMLHTTPRequest对象的open方法 - 设置回调函数 ...

  3. jquery发送put请求_浅谈GET,POST,PUT发送请求

    一般我们在浏览器的地址栏输入网址回车后,发送的是GET请求 当用表单提交时(最普遍的是用户登录),我们可以指定是GET还是POST请求,这里需要注意的是有的浏览器并不支持PUT请求,那后台restfu ...

  4. python并发发送http请求_用python异步发送http请求来提升效率

    需求 在一个我做的项目里,业务流程有一环需要调用http的接口. 这个接口本身是同步处理的,返回响应的速度会根据要处理的数据量不同而不同. 为了不拖慢主业务流程,客户要求采用异步的方式来请求,即只要得 ...

  5. axios创建实例对象发送ajax请求_解决一个网页请求多个服务器场景---axios工作笔记009

    然后我们再去看看,我们利用 axios去创建实例对象来发送ajax请求 可以看到上面我们创建了一个duanzi的axios对象. 然后我们在这个duanzi的axios对象中,指定默认的baseURL ...

  6. 取消发送option请求_【JavaWeb】HTTP协议的请求与响应

    HTTP协议 超文本传输协议 Hyper Text Transfer Protocol HTTP的作用 规范浏览器与服务器的数据交换的格式思考:没有HTTP协议会怎样?没有 HTTP 协议也可以,但是 ...

  7. jquery发送ajax请求_复习之Vue用axios发送ajax请求

    Axios是一个基于promise的HTTP库. 浏览器支持情况:Chrome.Firefox.Safari.Opera.Edge.IE8+. 官网:https://github.com/axios/ ...

  8. python token发送请求_使用Python发送请求

    本节内容# requests安装 requests使用 JSON类型解析 requests库详解 带安全认证的请求 序言# 上节课我们学习了接口测试的理论,抓包工具及使用Postman手工测试各种接口 ...

  9. Ajax--概述、xhr对象的常用属性和方法、xhr的常用事件、xhr对象发送POST请求、xhr对象发送GET请求、xhr对象的兼容性问题、数据交换格式(XML、JSON)

    一.概述 1.1 发展历程 在开始之前先来看一下Ajax的工作原理吧,如下图所示: Ajax全称Asynchronous javascript and xml(异步 JavaScript 和 XML) ...

最新文章

  1. 易生信高级转录组分析和数据可视化-最后一天报名
  2. 用iframe设置代理解决ajax跨域请求问题
  3. python单行箭头_python – 如何在matplotlib的曲线末端放置一个箭头?
  4. 电子商务javaweb b2b b2c o2o平台
  5. 如何在Eclipse中查看Android源码或者第三方组件包源码
  6. 获取本地的json并展示
  7. StarUML启动报RPC服务器不可用错误
  8. php抓取页面生成html,PHP smiple html dom抓取页面内容
  9. 几个优化 Cacti 监控服务性能的技巧
  10. LeetCode946-验证栈序列
  11. plsql怎么用字段查表明_PLSQL查询语句
  12. 【GPU+ubuntu】Ubuntu下的Tensorflow-gpu等各种环境和包的安装
  13. Android 学习心得体会
  14. 接口测试基本操作与常用接口测试工具
  15. 原生 javascript 操作 websocket
  16. Java通过 JDBC 连接数据库操作
  17. 【知识梳理】《Kafka权威指南》知识梳理
  18. MagicDraw-状态机图
  19. Linux编辑器-vim的使用的 “打字练习“
  20. revit应用程序无法启动_Revit启动时显示”应用程序无法正确启动”应该如何解决?...

热门文章

  1. springboot能用python吗_Python与springboot的对接
  2. Linux打包软件版本带时间,带你写一个 linux 下的打包软件 tar
  3. java 数组写法_java书写、数据类型、数组定义
  4. Qt图形界面编程入门(Qt的历史、Qt安装资源链接、Qt Creator简介)
  5. Latex 调整表格大小 表格过大 表格过小
  6. Deepin安装最新显卡RTX2080Ti及CUDA10.1
  7. Go语言vscode环境配置
  8. mac上的mysql管理工具sequel pro
  9. 利用python进行数据分析D2——ch03IPython
  10. Javascript中Base64编码解码的使用实例