2016-02-11 320 views
1

我试图从Outlook使用与我的默认设置不同的Outlook地址发送传真。以下是我的代码。使用不同的Outlook电子邮件地址从Access发送电子邮件

谢谢。

私人小组FaxDoctor()“传真的医生信 对错误转到Error_Handler 昏暗FSO

Dim olApp As Object 

' Dim olApp As Outlook.Application 

Dim olNS As Outlook.NameSpace 
Dim olfolder As Outlook.MAPIFolder 
Dim olMailItem As Outlook.MailItem 
Set fso = CreateObject("Scripting.FileSystemObject") 

If fso.FileExists("\\pna434h0360\PharmServ\Output\" & Me!ID & ".pdf") Then ' If the filename is found 
    Set olApp = CreateObject("Outlook.Application") 
    Set olNS = olApp.GetNamespace("MAPI") 
    Set olfolder = olNS.GetDefaultFolder(olFolderInbox) 
    Set olMailItem = olfolder.Items.Add("IPM.Note") 
    olMailItem.display 
    With olMailItem 
     .Subject = " " 
     .To = "[fax:" & "Dr. " & Me.[Prescriber First Name] & " " & Me.[Prescriber Last Name] & "@" & 1 & Me!Fax & "]" ' Must be formatted exactly to be sent as a fax 
     '.Body = "This is the body text for the fax cover page" ' Inserts the body text 
     .Attachments.Add "\\pna434h0360\PharmServ\Output\" & Me!ID & ".pdf" ' attaches the letter to the e-mail/fax 
     '.SendUsingAccount = olNS.Accounts.Item(2) 'Try this to change email accounts 
    End With 

    Set olMailItem = Nothing 
    Set olfolder = Nothing 
    Set olNS = Nothing 
    Set olApp = Nothing 
Else 
    GoTo Error_Handler 
End If 

Exit_Procedure: 上的错误继续下一步 退出小组 Error_Handler: MSGBOX(”无字母找到“& vbCrLf &”如果您确定这封信是以正确的文件名保存的,请关闭Outlook并再试一次。“)”这经常崩溃,因为没有找到该信件或因为outlook崩溃。在这种情况下,应关闭每个Outlook进程并重新启动Outlook。 Exit Sub End Sub

回答

0

您可以使用邮件项目的'SendUsingAccount'属性更改Outlook帐户。这需要设置为一个帐户对象。

您可以使用类似这样的方式设置给定名称的帐户,其中'AccountName'是您要发送的地址。

Dim olAcc as Outlook.Account 

For Each olAcc In Outlook.Session.Accounts 
    If outAcc.UserName = 'AccountName' Then 
     olMailItem.SendUsingAccount = outAcc 
     Exit For 
    End If 
Next 
0

使用 “.SendOnBehalfOfName”

我发现这个功能上线,所以只要按照其领先地位尝试:

Function SendEmail() 

Dim Application As Outlook.Application 
Dim NameSpace As Outlook.NameSpace 

Dim SafeItem, oItem ' Redemption 

Set Application = CreateObject("Outlook.Application") 

Set NameSpace = Application.GetNamespace("MAPI") 

NameSpace.Logon 


Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem 
Set oItem = Application.CreateItem(0) 'Create a new message 
SafeItem.Item = oItem 'set Item property 
SafeItem.Recipients.Add "[email protected]" 
SafeItem.Recipients.ResolveAll 
SafeItem.Subject = "Testing Redemption" 
SafeItem.SendOnBehalfOfName = "[email protected]" 

SafeItem.Send 

End Function 
相关问题