Use Ruby to capture page content and send an email

Source: Internet
Author: User

It is very easy to use Ruby to get the page content. I checked the information and tried to write an email sending code. It seems that Ruby is used to implement "Java calls jruby to get webpage content (jdk1.5) "The requirement in this article is more convenient. The Code is as follows:

 

Require 'net/http'
Require 'uri'
Require "net/SMTP"
STR = net: http. Get (URI. parse ('HTTP: // www.google.cn '));
# Puts Str
Def sendemail (subject, content, to = nil)
From = "Youremail@163.com"
To = ["xxx@qq.com", "xxx2@qq.com"] If to. nil?
Sendmessage = "Subject:" + Subject + "/n" + content

# Parameter description: 'Your. SMTP. Server', 25, 'mail. From. Domain ', 'Your account', 'Your password', authtype

SMTP = net: SMTP. Start ('smtp .163.com ', 25, '2017. com', Youremail@163.com', 'xxxxx',: Login)
SMTP. send_message sendmessage, from,
SMTP. Finish
End

Sendemail ("test", STR, nil)
Puts ("-- send OK ----");

 

SMTP supports three authentication parameters:

1): Plain

2): Login

3): cram_md5

 

Is it concise? ^-^

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.