该脚本(使用Outlook发送电子邮件)如何工作? [英] How does this script (sending email using Outlook) work?

查看:208
本文介绍了该脚本(使用Outlook发送电子邮件)如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我了解MAPI的工作原理吗?我有一个使用MAPI发送电子邮件的简单vbscript.它工作得很好,但是,我不知道它是怎么做的……背景中发生了什么?

Can anyone help me understand how MAPI works? I have this simple vbscript that uses MAPI to send an email out. It works perfectly fine, but, I don't know how it is doing that...what's happening in the background?

Const ForReading = 1

Set args = WScript.Arguments
sqlFile = args.Item(0)
logFile = args.Item(1)

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
MyTime = Now

ToAddress = "my@email.com"
MessageSubject = "Subject goes here"
MessageBody = "Body message goes here." 
MessageAttachment = ""&logFile&""
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send

预先感谢...

推荐答案

上面这段代码中的操作实际上是使用已安装的Outlook版本发送邮件. Outlook可能很好地使用MAPI,但是您实际上在这里使用的API接口是基于COM的Outlook自动化.这样的代码将利用Outlook通过可配置为使用Outlook的任何邮件传输系统发送电子邮件.但是,仅发送电子邮件消息会产生大量开销.根据您可能在网络上或通过网络拥有的本地电子邮件服务器,可能会有更有效的发送电子邮件的方法.但是,如果这种方法行之有效,并且当前可以满足您的需求,请不要认为这样做与上面的方式有什么关系.一切都是关于了解您可以使用的工具以及如何将其最佳地应用于您的特定问题空间的.

What you are doing in this code above is actually using the installed version of Outlook to send the mail message. Outlook may very well be using MAPI, but the API interface you are actually using here is COM based automation of Outlook. Code such as this will utilize Outlook to send email through any mail transportation system that Outlook can be configured to use. However, that is a lot of overhead just to send an email message. Depending on what email server(s) you might have local to you on your network or via there may be much more efficient ways to send email. But if this works fine and meets your needs currently, don't take that to mean that there is anything wrong with doing it the way you have above. It is all about understanding the tools available to you and how to best apply them to your particular problem space.

在您的代码中,您正在控制Outlook并告诉它创建电子邮件.您将邮件传递给Outlook,然后Outlook实际上正在使用配置的配置文件,它必须确定如何将邮件传递给配置的Exchange服务器或其他已安装/配置的邮件传输代理(mta).

In your code, you are controlling Outlook and telling it to create an email message. You are passing off the message to Outlook and then Outlook is actually using the configured profile it has to determine how to hand off the message to a configured Exchange server or other installed/configure mail transport agents (mta).

这篇关于该脚本(使用Outlook发送电子邮件)如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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