无法通过微软访问2007向多个收件人发送电子邮件,仅发送给第一个收件人

时间:2013-06-24 03:25:06

标签: ms-access-2007 access-vba lotus-notes

我想通过微软访问界面静默发送电子邮件。用户只需在列表框中选择收件人,然后单击一个按钮即可将电子邮件发送给多个收件人。我不希望莲花笔记界面出现在用户面前。我使用这些命令发送电子邮件没有问题:

 DoCmd.SendObject objecttype:=acSendTable, _
 objectname:=strDocName, outputformat:=acFormatXLS, _
 To:=strEmail, Subject:=strMailSubject, MessageText:=strMsg, EditMessage:=False

但这些方法不是我想要的,因为它会在发送电子邮件时出现在屏幕上。虽然我已经设置了EditMessage:= False。

我有一个程序,通过后台的莲花笔记从访问中发送电子邮件。单个收件人的程序运行正常,但如果我选择多个收件人,它只会向一个收件人发送电子邮件。我认为这个问题与收件人字符串有关。 收件人字符串示例:

eg1 : duwey@yahoo.com, mridzuan@gmail.com, mridzuan@yahoo.com

eg2 : duwey@yahoo.com; mridzuan@gmail.com; mridzuan@yahoo.com

电子邮件将仅发送给第一位收件人

这是子程序:

Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)

Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'The current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)

Set Session = CreateObject("Notes.NotesSession")

'Get the sessions username and then calculate the mail file name
UserName = Session.UserName

MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"

'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)

If Maildb.ISOPEN = False Then
   Maildb.OPENMAIL
End If

'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT

MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText & vbCrLf & vbCrLf
MailDoc.PostedDate = Now()
MailDoc.SAVEMESSAGEONSEND = SaveIt

'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
   Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
   Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
   MailDoc.CREATERICHTEXTITEM ("Attachment")
End If

'Send the document
MailDoc.send 0, Recipient

'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing

End Sub

按钮点击事件调用电子邮件程序:

Private Sub cmdSendEmail_Click()

Dim EmailSubject As String, EmailAttachment As String, EmailRecipient As String, EmailBodyText As String, EmailSaveIt As Boolean

EmailSubject = Me.txtSubject.Value
EmailAttachment = Me.txtAttachment.Value
EmailRecipient = Me.txtSelected.Value
EmailBodyText = Me.txtMessage.Value
EmailSaveIt = True

Call SendNotesMail(EmailSubject, EmailAttachment, EmailRecipient, EmailBodyText, EmailSaveIt)

End Sub

以下是我如何从列表框中获取多个收件人字符串:

Private Sub lstEmail_Click()

On Error Resume Next
Dim varItem As Variant
Dim strList As String

With Me.lstEmail
  If .MultiSelect = 0 Then
     Me.txtSelected = .Value
  Else
     For Each varItem In .ItemsSelected
         strList = strList & .Column(0, varItem) & ", "
     Next varItem
     strList = Left$(strList, Len(strList) - 2) 'eliminate ", " at the end of recipient's string
     Me.txtSelected.Value = strList

   End If
 End With
End Sub

我真的不能使用docmd.sendObject方法,因为它仍然出现在屏幕上,虽然我设置了EditMessage:= False。我不知道它是否适用于其他电子邮件,但我的莲花笔记8.5不适用于docmd.sendObject用于在后台发送电子邮件。 任何帮助或建议?

1 个答案:

答案 0 :(得分:3)

收件人字段必须是一个arraylist)。你能用split来把它变成一个数组吗?

MailDoc.sendto = split(Recipient, ", ")