|
如题,求教各位老师,我现在outlook有两个不同的账户,希望能用vba调用不同的账户去发送邮件,求指教,我现在用的vba代码如下:Public Sub SendMail(ByVal strTo As String, ByVal strCC As String, ByVal strSubject As String, ByVal strBody As String, Optional ByVal strAttach1 As String, Optional ByVal strAttach2 As String, Optional ByVal strAttach3 As String)
Dim Outlook As Outlook.Application
Dim NewMail As mailitem
'Dim strTo, strCC, strSubject, strBody, strAttach As String
Dim otlk As Outlook.Application
Dim mailitem As Outlook.mailitem
Dim signature As String
Set Outlook = CreateObject("outlook.application")
Set NewMail = Outlook.CreateItem(olMailItem)
On Error GoTo errHandle
Set otlk = New Outlook.Application
Set mailitem = otlk.CreateItem(olMailItem)
signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(signature, vbDirectory) <> vbNullString Then
signature = signature & Dir$(signature & "*.htm")
Else:
signature = ""
End If
signature = CreateObject("Scripting.FileSystemObject").GetFile(signature).OpenAsTextStream(1, -2).ReadAll
With mailitem
.To = strTo
.CC = strCC
.Subject = strSubject
If InStr("Important", strSubject) > 0 Then
.Importance = olImportanceHigh
End If
.HTMLBody = strBody & signature
If Len(strAttach1) <> 0 Then .Attachments.Add strAttach1
If Len(strAttach2) <> 0 Then .Attachments.Add strAttach2
If Len(strAttach3) <> 0 Then .Attachments.Add strAttach3
.Send
End With
Do Until mailitem.Sent = True
DoEvents
Loop
end sub
|
|