通过Outlook从命令行发送电子邮件,而无需点击发送 [英] Sending email from Command-line via outlook without having to click send
问题描述
我需要通过命令行来发送电子邮件而无需任何的自动化人工交互。
I need to send email via command-line without any human interactions for automation.
我知道我们可以使用的mailto命令,但将编写电子邮件,主题,正文和一切,但除非我点击发送就不会发送。
I know we can use mailto command but that would compose email, subject,body and everything but it wouldn't send it unless I click send.
我看网上,我们可以使用BLAT,但我不能使用非Outlook东西。
I read online we can use blat but I cannot use anything other than outlook.
我甚至做了谷歌的研究整整一天,但昨天没有解决呢。
I've even did Google research whole day yesterday but no solution yet.
这是封闭的文章中,我已经找到<一个href=\"http://stackoverflow.com/questions/248569/starting-outlook-and-having-an-email-$p$p-populated-from-command-line/248598?noredirect=1#comment21827342_248598\">Link到SOF帖子。
This is closed post I have found Link to SOF post.
任何帮助将是有益的。
仅供参考:我期待到一些Telnet命令来发送电子邮件没有得到在尚未成功要么。
Telnet命令来发送电子邮件
just fyi: I am looking into some telnet commands to send email haven't gotten success in that yet either. telnet commands to send email
推荐答案
选项1 结果
你没有说太多关于你的环境,但假设你拥有它提供您可以使用PowerShell脚本;一个例子是这里。这样做的本质是:
Option 1
You didn't say much about your environment, but assuming you have it available you could use a PowerShell script; one example is here. The essence of this is:
$smtp = New-Object Net.Mail.SmtpClient("ho-ex2010-caht1.exchangeserverpro.net")
$smtp.Send("reports@exchangeserverpro.net","administrator@exchangeserverpro.net","Test Email","This is a test")
您可以然后在命令行启动脚本按照这个例子:
You could then launch the script from the command line as per this example:
powershell.exe -noexit c:\scripts\test.ps1
需要注意的是PowerShell 2.0中,这是在默认情况下安装在Windows 7和Windows Server 2008 R2,包括简单的 发送 - MAILMESSAGE
命令,使事情变得更容易。
Note that PowerShell 2.0, which is installed by default on Windows 7 and Windows Server 2008R2, includes a simpler Send-MailMessage
command, making things easier.
选项2 结果
如果你ppared使用第三方软件$ P $,东西线此SendEmail命令 - 行工具。这取决于你的目标环境,虽然,如果您正在部署您的批处理文件到多台计算机,这显然需要包括(但不是正式的安装)各一次。
Option 2
If you're prepared to use third-party software, is something line this SendEmail command-line tool. It depends on your target environment, though; if you're deploying your batch file to multiple machines, that will obviously require inclusion (but not formal installation) each time.
选项3 结果
你可以直接从VBA脚本,这反过来你会从一个批处理文件触发带动展望;这将让你使用Outlook发送本身,它看起来最接近是你想要什么样的电子邮件。有两个部分本;首先,弄清楚发送电子邮件所需的VBA编写脚本。有很多的例子对这个网上,其中包括来自这里微软。这实质是:
Option 3
You could drive Outlook directly from a VBA script, which in turn you would trigger from a batch file; this would let you send an email using Outlook itself, which looks to be closest to what you're wanting. There are two parts to this; first, figure out the VBA scripting required to send an email. There are lots of examples for this online, including from Microsoft here. Essence of this is:
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." &vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
For Each ObjOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Save
.Send
End With
Set objOutlook = Nothing
End Sub
然后,从与 /自动运行
参数从命令行启动Outlook中,按的这个答案(改变路径/必要的宏名):
Then, launch Outlook from the command line with the /autorun
parameter, as per this answer (alter path/macroname as necessary):
C:\Program Files\Microsoft Office\Office11\Outlook.exe" /autorun macroname
选项4 结果
您可以使用相同的方法选择3,但移动在Outlook VBA到PowerShell脚本(你会从一个命令行运行)。例如<一个href=\"http://blogs.msdn.com/b/jmanning/archive/2007/01/25/using-powershell-for-outlook-automation.aspx\"相对=nofollow>此处。这可能是最整洁的解决方案,海事组织。
Option 4
You could use the same approach as option 3, but move the Outlook VBA into a PowerShell script (which you would run from a command line). Example here. This is probably the tidiest solution, IMO.
这篇关于通过Outlook从命令行发送电子邮件,而无需点击发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!