【发布时间】:2021-07-09 08:06:52
【问题描述】:
我想发送带有 excel 宏的电子邮件。我在一些网站上阅读过同样简单的 VBA 代码,它可以发送带有附件的电子邮件。
Sub Send_Email_via_Lotus_Notes()
Dim Maildb As Object
Dim MailDoc As Object
Dim Body As Object
Dim Session As Object
'Start a session of Lotus Notes
Set Session = CreateObject("Lotus.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
Call Session.Initialize
'or use below to provide password of the current ID (to avoid Password prompt)
'Call Session.Initialize("<password>")
'Open the Mail Database of your Lotus Notes
Set Maildb = Session.GETDATABASE("", "D:\Notes\data\Mail\eXceLiTems.nsf")
If Not Maildb.IsOpen = True Then Call Maildb.Open
'Create the Mail Document
Set MailDoc = Maildb.CREATEDOCUMENT
Call MailDoc.REPLACEITEMVALUE("Form", "Memo")
'Set the Recipient of the mail
Call MailDoc.REPLACEITEMVALUE("SendTo", "Ashish Jain")
'Set subject of the mail
Call MailDoc.REPLACEITEMVALUE("Subject", "Subject Text")
'Create and set the Body content of the mail
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("Body text here")
'Example to create an attachment (optional)
Call Body.ADDNEWLINE(2)
Call Body.EMBEDOBJECT(1454, "", "C:\dummy.txt", "Attachment")
'Example to save the message (optional) in Sent items
MailDoc.SAVEMESSAGEONSEND = True
'Send the document
'Gets the mail to appear in the Sent items folder
Call MailDoc.REPLACEITEMVALUE("PostedDate", Now())
Call MailDoc.SEND(False)
'Clean Up the Object variables - Recover memory
Set Maildb = Nothing
Set MailDoc = Nothing
Set Body = Nothing
Set Session = Nothing
End Sub
设置 Maildb = Session.GETDATABASE("", "D:\Notes\data\Mail\eXceLiTems.nsf") 在我工作的笔记本电脑上有 10 个 nsf 文件。我不知道我应该在第二个参数中输入哪个。 我已经阅读了这里的语法:https://help.hcltechsw.com/dom_designer/9.0.1/appdev/H_GETDATABASE_METHOD.html
两者都可以是空字符串。如果我使用空字符串,如果我是正确的,它会创建一个新数据库。因为我想每天发送 5 封电子邮件,所以我想在 for 循环中发送电子邮件。如果我使用空字符串,代码会每天创建 5 个数据库吗?我认为是的,所以我认为我需要使用 10 个 nsf 文件之一作为第二个参数,所以它不会创建,但我不想让我的笔记帐户崩溃。 我对笔记很陌生。我用vba for outlook发邮件,没有数据库参数。
【问题讨论】: