通过VBA发送电子邮件 [英] Send e-mail through VBA
问题描述
Sub CreateHTMLMail()
'创建一个新的电子邮件项目并修改其属性
Dim olApp作为Outlook.Application
Dim objMail As Outlook .MailItem
设置olApp = Outlook.Application
'创建电子邮件项
设置objMail = olApp.CreateItem(olMailItem)
带objMail
.Subject =Test Message
.Body =Body Text
.Recipients.Addxyz@abc.com
.Recipients.ResolveAll
.Display
结束
End Sub
当我运行这个我收到一个运行时错误'287'消息与.Recipients.Add行突出显示当我选择调试。如果我拿出.recipients行代码工作,并显示一个具有正确标题和正文的邮件,但我无法得到它来添加收件人。有没有人知道我在做错什么?
提前感谢您的帮助。
Steve
尝试这样:
toString =me@email.com; you@email.com; them@email.com
带OutMail
.To = toString
.Subject =你好朋友
.Body =这是电子邮件正文
。发送
结束
这当然适用于多个收件人。对于单个收件人,只需执行以下操作:
toString =oneguy@gmail.com
不要忘记 .Send
来实际发送电子邮件。 / p>
I am currently testing how to send an e-mail automatically using VBA within Outlook 2003, to start I have copied the below from the help files:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties'
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
'Create e-mail item'
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.Subject = "Test Message"
.Body = "Body Text"
.Recipients.Add "xyz@abc.com"
.Recipients.ResolveAll
.Display
End With
End Sub
When I run this I receive a Runtime error '287' message with the .Recipients.Add line highlighted when I select debug. If I take out the .recipients lines the code works and displays a mail with the correct title and body text but I cannot get it to add the recipients. Does anybody know what I am doing wrong?
Thanks in advance for your help. Steve
Try this:
toString = "me@email.com;you@email.com;them@email.com"
With OutMail
.To = toString
.Subject = "Hello Friends"
.Body = "Here is the email body"
.Send
End With
This of course works with multiple recipients. For a single recipient, just do this:
toString = "oneguy@gmail.com"
And don't forget the .Send
to actually make your email send.
这篇关于通过VBA发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!