- 浏览: 538335 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
小灯笼:
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 977gem install mysql -v 2.8.1 最新 ... -
rspec2的返回值验证方法
2014-05-06 13:34 697s="response string" ... -
ruby实现一个文件各行顺序打乱
2013-12-16 15:11 963对于传递参数很有用,代码如下 arr=Array.new ... -
ruby to play mp3 on windows
2012-08-09 16:00 1084the simplest way is to call by ... -
ruby静态方法hook
2012-06-26 14:07 1441静态方法和实例方法的实现方式不一样,代码如下: cl ... -
ruby最简单的方式对数组求和
2012-06-18 17:21 2954通过循环来求和代码看上去不太优雅,不符合ruby的特性。推荐另 ... -
ruby按精度保留小数
2012-06-18 17:17 1554有一个round函数,用起来非常方便: >> ... -
Ruby更改gem source
2012-04-17 16:56 34674很多时候,在安装gem的过程中会出现找不到资源的erro ... -
Ruby通过win32ole调用操作系统接口
2012-04-16 13:23 23851 Word require 'win32ol ... -
Ruby修改yaml文件
2012-03-09 14:16 1937需要注意save之后调用close方法, 否则可能只有第一次会 ... -
Ruby命令运行rspec程序
2012-02-13 16:13 1262任何ruby gem的命令都可以写成ruby的运行方式, rp ... -
怎样在Eclipse里面调试ruby子进程?
2012-02-09 17:57 1741有两个ruby文件main.rb和sub.rb。 ma ... -
Ruby怎样自定义命令
2012-02-08 14:39 12361 首先在ruby根路径下面的bin目录建立2个文件: yan ... -
解决eclispe中ruby-debug-ide19找不到路径
2012-02-02 16:10 1288找到ruby-debug-ide文件,更改 bt = ... -
怎样调试纯Ruby程序
2012-02-02 14:26 1572有两个版本, 命令行的和IDE支持的 安装方法: ... -
六种用ruby调用执行shell命令的方法
2012-01-20 13:05 877原文来自: http://blackanger.blog. ... -
Ruby读写文件
2012-01-16 10:53 18691. 读取 File.open("C:\\t ... -
Ruby中的%表示法(百分号表示法)
2012-01-16 10:47 1034转自: 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 1180原文来自: http://stackoverflow.com/ ... -
Ruby怎样require整个文件夹
2012-01-09 16:00 1369dir = File.dirname(__FILE__) ...
相关推荐
这个库使得在Ruby应用程序中创建、解析、发送和接收邮件变得轻而易举。Mail库提供了丰富的功能,包括解析MIME(多用途互联网邮件扩展)格式的邮件,支持附件,以及对邮件头和内容的全面操作。 ### 1. MIME处理 ...
**Ruby-Mailman:一个高效的邮件接收与处理框架** Ruby-Mailman 是一个专门为 Ruby 开发者设计的轻量级邮件处理微框架。它旨在简化邮件服务器接收到的电子邮件的处理流程,帮助开发者构建邮件相关的应用程序,如...
Logging email appender 提供了一种从 Ruby 应用程序通过电子邮件发送日志消息的方法。 如果您希望在出现异常或致命错误时收到通知,这将非常有用。 电子邮件附加程序最初是 Logging 框架的一部分,但随着 Logging ...
这是因为许多邮件客户端(如Gmail、Outlook)出于安全考虑,会忽略嵌入在`<head>`标签内的`<style>`块,而优先支持内联样式。通过将CSS转换为内联样式,可以确保邮件在各种客户端中保持一致的视觉效果。 ### 2. ...
在 config/environments/development.rb 中更改 Gmail (不包括 @gmail.com)和 <password> 更改 <email> lib/tasks/sendemailnow.rake rake sendemailnow
- **其他语言**:C#有`System.Net.Mail`,PHP有`imap`函数库,Ruby有`mail` gem等。 3. **授权与身份验证** - **基本认证**:用户名和密码直接传输,不安全,应避免在公共网络中使用。 - **OAuth2**:谷歌和微软...
收件箱 描述 在开发和测试模式下预览发送电子邮件。...导航到/inbox/<email>/emails例如: /inbox/robert.pankowecki@gmail.com/emails以查看将发送给用户的电子邮件列表。 单击电子邮件主题以查看
用法有一些默认值: $ ./notify_of_new_gist_comments github_username recipient_email sender_email email_password这将仅通知公共/tmp/gist-notifications-last-run-time ,将使用smtp.gmail.com发送您的电子邮件...
Crystal是一种现代、快速且静态类型的编程语言,它设计的目标是易于阅读和编写,同时保持了Ruby的语法风格。在Crystal中处理电子邮件涉及的主要概念和技术包括SMTP(Simple Mail Transfer Protocol)和邮件服务器的...
#Sample 管理员角色用户注册+访问限制+试错记录旨在实现管理屏幕#实现的功能1个用户,1个权限链接用户模型和角色模型注册为用户时-> devise发送邮件,踩下...PORT=587export EMAIL_DOMAIN=gmail.comexport SMTP_AUTH=pl
它使用 ERB 来呈现电子邮件,并使用与您的 GMail(或 Google Apps)帐户关联的 SMTP 服务器来发送它们。 设置 克隆这个存储库: git clone https://github.com/mygulamali/secret_bambino.git 安装所需的宝石: ...
3. **email** - 表明这个项目与电子邮件的处理和发送有关。 4. **html-emails** - 明确指出项目关注的是 HTML 格式的电子邮件。 5. **ElixirElixir** - 这个标签可能是个误打,但重复强调了项目使用 Elixir 语言的...
Sinatra是一个轻量级的Ruby web框架,用于构建快速、简洁和灵活的web应用。在这里,emailChecker应用扮演了后台服务的角色,接收来自Chrome扩展的请求,然后根据LinkedIn用户的信息尝试推断出可能的电子邮件地址。...
类似于GMail的以线程为中心的归档,标记和静音 使用快速的全文本搜索 多个帐户-发送邮件时选择正确的帐户 自动跟踪最近的联系人 当前限制: Sup通常不能与其他邮件客户端很好地协作,并非所有更改都可以同步回邮件...