[英]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.