- 浏览: 528382 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
小灯笼:
Selenium自动化测试实战网盘地址:https://pan ...
selenium对flex程序的自动化测试 -
noizz:
linux下也有效碰到一个snv update无法识 ...
解决jenkins控制台中文乱码问题 -
liuweihug:
图说浏览器的缓存原理及缓存方式说明(1) http://www ...
终于弄清楚浏览器的缓存机制了 -
dayudodo:
或者再简单一上些,直接在Gemfile中添加gem 'thin ...
运行thin start报错的解决方法 -
tiroc:
试一下这样:
group :development do
...
运行thin start报错的解决方法
ruby-gmail
- Homepage: http://dcparker.github.com/ruby-gmail/
- Code: http://github.com/dcparker/ruby-gmail
- Gem: http://gemcutter.org/gems/ruby-gmail
Author(s)
- Daniel Parker of BehindLogic.com
Extra thanks for specific feature contributions from:
Description
A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and send multipart emails; archive, mark as read/unread, delete emails; and manage labels.
Features
- Search emails
- Read emails (handles attachments)
- Emails: Label, archive, delete, mark as read/unread/spam
- Create and delete labels
- Create and send multipart email messages in plaintext and/or html, with inline images and attachments
- Utilizes Gmail's IMAP & SMTP, MIME-type detection and parses and generates MIME properly.
Problems:
- May not correctly read malformed MIME messages. This could possibly be corrected by having IMAP parse the MIME structure.
- Cannot grab the plain or html message without also grabbing attachments. It might be nice to lazy-[down]load attachments.
Example Code:
1) Require gmail
require 'gmail'
2) Start an authenticated gmail session
# If you pass a block, the session will be passed into the block,
# and the session will be logged out after the block is executed.
gmail = Gmail.new(username, password)
# ...do things...
gmail.logout
Gmail.new(username, password) do |gmail|
# ...do things...
end
3) Count and gather emails!
# Get counts for messages in the inbox
gmail.inbox.count
gmail.inbox.count(:unread)
gmail.inbox.count(:read)
# Count with some criteria
gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
gmail.inbox.count(:on => Date.parse("2010-04-15"))
gmail.inbox.count(:from => "myfriend@gmail.com")
gmail.inbox.count(:to => "directlytome@gmail.com")
# Combine flags and options
gmail.inbox.count(:unread, :from => "myboss@gmail.com")
# Labels work the same way as inbox
gmail.mailbox('Urgent').count
# Getting messages works the same way as counting: optional flag, and optional arguments
# Remember that every message in a conversation/thread will come as a separate message.
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
4) Work with emails!
# any news older than 4-20, mark as read and archive it...
gmail.inbox.emails(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
email.mark(:read) # can also mark :unread or :spam
email.archive!
end
# delete emails from X...
gmail.inbox.emails(:from => "x-fiancé@gmail.com").each do |email|
email.delete!
end
# Save all attachments in the "Faxes" label to a folder
folder = "/where/ever"
gmail.mailbox("Faxes").emails.each do |email|
if !email.attachments.empty?
email.save_attachments_to(folder)
end
end
# Save just the first attachment from the newest unread email (assuming pdf)
# For #save_to_file:
# + provide a path - save to attachment filename in path
# + provide a filename - save to file specified
# + provide no arguments - save to attachment filename in current directory
email = gmail.inbox.emails(:unread).first
email.attachments[0].save_to_file("/path/to/location")
# Add a label to a message
email.label("Faxes")
# Or "move" the message to a label
email.move_to("Faxes")
5) Create new emails!
Creating emails now uses the amazing Mail rubygem. See its documentation here. Ruby-gmail will automatically configure your Mail emails to be sent via your Gmail account's SMTP, so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From" email either, because ruby-gmail will set it for you.
gmail.deliver do
to "email@example.com"
subject "Having fun in Puerto Rico!"
text_part do
body "Text of plaintext message."
end
html_part do
body "<p>Text of <em>html</em> message.</p>"
end
add_file "/path/to/some_image.jpg"
end
# Or, generate the message first and send it later
email = gmail.generate_message do
to "email@example.com"
subject "Having fun in Puerto Rico!"
body "Spent the day on the road..."
end
email.deliver!
# Or...
gmail.deliver(email)
Requirements
- ruby
- net/smtp
- net/imap
- tmail
- shared-mime-info rubygem (for MIME-detection when attaching files)
发表评论
-
ruby安装mysql驱动报错问题
2014-11-11 16:47 911gem install mysql -v 2.8.1 最新 ... -
rspec2的返回值验证方法
2014-05-06 13:34 662s="response string" ... -
ruby实现一个文件各行顺序打乱
2013-12-16 15:11 932对于传递参数很有用,代码如下 arr=Array.new ... -
ruby to play mp3 on windows
2012-08-09 16:00 1051the simplest way is to call by ... -
ruby静态方法hook
2012-06-26 14:07 1391静态方法和实例方法的实现方式不一样,代码如下: cl ... -
ruby最简单的方式对数组求和
2012-06-18 17:21 2911通过循环来求和代码看上去不太优雅,不符合ruby的特性。推荐另 ... -
ruby按精度保留小数
2012-06-18 17:17 1506有一个round函数,用起来非常方便: >> ... -
Ruby更改gem source
2012-04-17 16:56 34573很多时候,在安装gem的过程中会出现找不到资源的erro ... -
Ruby通过win32ole调用操作系统接口
2012-04-16 13:23 23321 Word require 'win32ol ... -
Ruby修改yaml文件
2012-03-09 14:16 1872需要注意save之后调用close方法, 否则可能只有第一次会 ... -
Ruby命令运行rspec程序
2012-02-13 16:13 1213任何ruby gem的命令都可以写成ruby的运行方式, rp ... -
怎样在Eclipse里面调试ruby子进程?
2012-02-09 17:57 1705有两个ruby文件main.rb和sub.rb。 ma ... -
Ruby怎样自定义命令
2012-02-08 14:39 11771 首先在ruby根路径下面的bin目录建立2个文件: yan ... -
解决eclispe中ruby-debug-ide19找不到路径
2012-02-02 16:10 1238找到ruby-debug-ide文件,更改 bt = ... -
怎样调试纯Ruby程序
2012-02-02 14:26 1520有两个版本, 命令行的和IDE支持的 安装方法: ... -
六种用ruby调用执行shell命令的方法
2012-01-20 13:05 830原文来自: http://blackanger.blog. ... -
Ruby读写文件
2012-01-16 10:53 18061. 读取 File.open("C:\\t ... -
Ruby中的%表示法(百分号表示法)
2012-01-16 10:47 999转自: http://hi.baidu.com/hbxiao1 ... -
Defining “method_called”.. How do I make a hook method which gets called every t
2012-01-10 16:17 1126原文来自: http://stackoverflow.com/ ... -
Ruby怎样require整个文件夹
2012-01-09 16:00 1320dir = File.dirname(__FILE__) ...
相关推荐
SendCloud Ruby发送的SMTP_代码示例2,注:此为使用 SendCloud API V2 发送邮件的示例.
ruby短信接口开发_ruby发送短信验证码通知_ruby短信demo示例.docx
SendCloud Ruby模板发送&&地址列表代码示例,注:此为使用 SendCloud API V2 发送邮件的示例.
SendCloud Ruby普通发送代码示例,注:此为使用 SendCloud API V2 发送邮件的示例.
Ruby是一种纯粹的面向对象编程语言。它由日本的松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)创建于1993年。 您可以在 www.ruby-lang.org 的 Ruby 邮件列表上找到松本行弘(まつもとゆきひろ/Yukihiro Matsumoto...
这是linux版本下的ruby2.1.5版本,亲测可用,现在最新的版本
windows版本ruby运行环境安装,下载后解压即可,直接双击运行
Redis安装遇到错误解决方案Error installing redis: redis requires Ruby version >= 2.3.0. 先安装rvm,再把ruby版本提升至2.3.0
ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码
ruby 1.9.3 p484稳定版本,在windows上直接安装即可
SendCloud Ruby模板发送代码示例,注:此为使用 SendCloud API V2 发送邮件的示例.
SendCloud Ruby发送的SMTP_代码示例1,注:此为使用 SendCloud API V2 发送邮件的示例.
《Ruby元编程》PDF版本下载
SendCloud Ruby普通发送&&附件代码示例,注:此为使用 SendCloud API V2 发送邮件的示例.
ruby-build 是一个 rbenv 插件,它提供了一个 rbenv install 命令来在类 UNIX 系统上编译和安装不同版本的 Ruby。你还可以在需要精确控制 Ruby 版本安装的环境中使用不带 rbenv 的 ruby-build。用法在开始之前,...
ruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ...
sencha cmd 需要的第三方包,是一个完全面向对象的语言哟,堪比perl
本书详细介绍了Ruby 1.8和1.9版本各方面的内容。在对Ruby进行了简要的综述之后,本书详细介绍了以下内容:Ruby的句法和语法结构,数据结构和对象,表达式和操作符,语句和控制结构,方法、proc、lambda和闭包,反射...
Ruby 安装 - Windows 下面列出了在 Windows 机器上安装 Ruby 的步骤。 ... 如果一切工作正常,将会输出所安装的 Ruby 解释器的版本,如上所示。如果您安装了其他版本,则会显示其他不同的版本。
Ruby,一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言,在20世纪90年代由日本人松本行弘(Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、...