我使用此代码使用outlook发送电子邮件,但问题是我必须打开outlook然后才会发送消息。
我用.display但问题仍然相同。
提前致谢。
Private Sub btnSend_Click()
On Error GoTo errHandelrs
Dim oOutlook As Outlook.Application
Dim oeMailitem As MailItem
Dim rs As Recordset
Dim CustmrEmail As String
Dim n As Integer
If oOutlook Is Nothing Then
Set oOutlook = New Outlook.Application
End If
Set oeMailitem = oOutlook.CreateItem(olMailItem)
With oeMailitem
Set rs = CurrentDb.OpenRecordset("select *from tbl")
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
If IsNull(rs!Email) Then
rs.MoveNext
Else
CustmrEmail = CustmrEmail & rs!Email & ";"
.To = CustmrEmail
rs.MoveNext
End If
Loop
Else
MsgBox "nO bOdy"
End If
.CC = ""
.Subject = "mYSUbject"
For n = 0 To Me.list3.ListCount - 1
.Attachments.Add (Me.list3.ItemData(n))
Next n
.Send
End With
Exit_ErrHandelrs:
Exit Sub
errHandelrs:
MsgBox Err.Description, vbCritical
Resume Exit_ErrHandelrs
End Sub
答案 0 :(得分:0)
您可以同步帐户以确保发送电子邮件(并收到新电子邮件)。可以修改Outlook的发送/接收设置以更改其在交互式使用中的行为。
Dim oSyncObjects As Outlook.SyncObjects
Dim i As Long
Set oSyncObjects = oOutlook.GetNamespace("MAPI").SyncObjects
For i = 1 To oSyncObjects.Count
OSyncObjects.Item(i).Start
Next