简体   繁体   English

使用Ruby通过Outlook发送消息的最简单方法是什么?

[英]What's the easiest way to send a message through Outlook with Ruby?

My work requires me to automate e-mail generation for certain tests. 我的工作要求我为某些测试自动生成电子邮件。 I've been looking around but havent been able to find a reasonable solution that can be implemented quickly. 我一直在环顾四周,但还没找到一个可以快速实施的合理解决方案。 It needs to be in outlook and not some other mail server as we have some strange authentication rules in place, and we need the option of saving drafts instead of just sending the message. 它需要在outlook而不是其他邮件服务器,因为我们有一些奇怪的身份验证规则,我们需要选择保存草稿而不是发送消息。

Apparently win32ole can do this, but I can't find any reasonably simple examples. 显然win32ole可以做到这一点,但我找不到任何相当简单的例子。

Assuming that the Outlook credentials are stored and you are set to autologin to Outlook, WIN32OLE does the trick quite nicely: 假设存储了Outlook凭据并且您设置为自动登录到Outlook,WIN32OLE可以很好地完成这一操作:

require 'win32ole'
outlook = WIN32OLE.new('Outlook.Application')
message = outlook.CreateItem(0)
message.Subject = "Hey look a subject!"
message.Body = "Yes this is dog"
message.Recipients.Add 'dog@dog.com'
message.Recipients.Add 'cat@dog.com'
message.Attachments.Add('C:\Path\To\File.txt')
#Want to save as a draft?
message.Save
#Want to send instead?
message.Send

This is in fact quite well documented in " Automating Outlook with Ruby: Saving Mail Messages To Files ", as is automating the rest of windows with Ruby. 事实上,这在“ 使用Ruby自动化Outlook:将邮件保存到文件 ”中得到了很好的记录,就像使用Ruby自动化其余窗口一样。

You may have an authorization issue, which, if it appears, can be solved using " Advanced Security for Outlook ". 您可能遇到授权问题,如果出现问题,可以使用“ Advanced Security for Outlook ”解决。

If the Outlook account has web access (via outlook.com or office365.com) you can also use Mikel Lindsaar's Ruby email library . 如果Outlook帐户具有Web访问权限(通过outlook.com或office365.com),您还可以使用Mikel Lindsaar的Ruby电子邮件库 It works well for many different email providers that allow POP3, IMAP4, or SMTP connections. 它适用于允许POP3,IMAP4或SMTP连接的许多不同电子邮件提供商。

I posted an entry with some sample code on sending and receiving Outlook email via Ruby that might help. 我发布了一个带有一些示例代码的条目, 通过Ruby发送和接收Outlook电子邮件可能有所帮助。 Sorry, I can't comment on how to save drafts, though. 对不起,我无法评论如何保存草稿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Ruby中从CSV文件获取头文件的最简单方法是什么? - What's the easiest way to get the headers from a CSV file in Ruby? 在 Ruby 中,在字符串的开头而不是结尾处“chomp”的最简单方法是什么? - In Ruby, what's the easiest way to “chomp” at the start of a string instead of the end? 在本地设置红宝石/铁轨沙箱的最简单方法是什么? - what's the easiest way to setup a ruby/rails sandbox locally? 使用 Ruby 将 CSV 导出到 Excel 的最简单方法是什么? - What's the easiest way to export a CSV to Excel with Ruby? 在我的服务器上安装 Ruby 的最简单方法是什么 - What is the easiest way to install Ruby on my server 我很困惑,在OS X上安装Ruby 1.9.2的最简单方法是什么? - I'm confused, what's the easiest way to install Ruby 1.9.2 on OS X? 在没有混淆输出的情况下,在Ruby中从并行操作打印输出的最简单方法是什么? - What's the easiest way to print output from parallel operations in Ruby without jumbling up the output? 在Ruby中获取Lisp样式加法(+ * args)的最简单方法是什么? - What's the easiest way to get Lisp-Style addition (+ *args) in Ruby? 在ActiveResource中使用OAuth的最简单方法是什么? - What's the easiest way to use OAuth with ActiveResource? 在Ruby中使用独立的send方法的正确方法是什么? - What's the proper way to use an unattached send method in Ruby?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM