使用Ruby通过Outlook发送消息的最简单方法是什么? [英] What's the easiest way to send a message through Outlook with Ruby?

查看:203
本文介绍了使用Ruby通过Outlook发送消息的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作要求我为某些测试自动生成电子邮件.我一直在环顾四周,但还没有找到可以快速实施的合理解决方案.它必须在Outlook中,而不是其他邮件服务器中,因为我们有一些奇怪的身份验证规则,并且我们需要选择保存草稿而不是仅发送邮件.

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.

显然,win32ole可以做到这一点,但是我找不到任何相当简单的示例.

Apparently win32ole can do this, but I can't find any reasonably simple examples.

推荐答案

假设已存储Outlook凭据,并且您已设置为自动登录Outlook,则WIN32OLE可以很好地完成此操作:

Assuming that the Outlook credentials are stored and you are set to autologin to Outlook, WIN32OLE does the trick quite nicely:

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

事实上,这在"使用Ruby自动执行Outlook:将邮件保存到文件中",以及使用Ruby自动执行其余窗口的操作.

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.

您可能遇到授权问题,如果出现授权问题,可以使用"高级安全解决Outlook ".

You may have an authorization issue, which, if it appears, can be solved using "Advanced Security for Outlook".

这篇关于使用Ruby通过Outlook发送消息的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆