2012-05-23 73 views
0

我的客戶想要將excel/vba分發給他的客戶,vba會自動發送電子郵件。vba - 發送來自不同用戶的電子郵件

也許發件人應該是某個其他帳戶,而不是使用vba的人的outlook帳戶,因爲某些私人郵件可能在電子郵件中。真的有可能嗎?

另一件事是自動執行此類任務時發生的臭名昭着的彈出警告。當計算機被鎖定時,我聽到Application.SendKeys並不總是工作。

CDO如何完成此任務?

+0

可能重複[在Exchange環境中從Excel發送電子郵件](http://stackoverflow.com/questions/6122747/send-email-from-excel-in-exchange-environment) –

+0

Outlook版本? – JimmyPena

回答

1

在您最初的問題,你可以使用MailItem.SentOnBehalfOfName與Outlook

在安全警告Outlook的標準兩種解決方案:
1)使用Clickyes
2)安裝Outlook Redemption

+0

+ 1 :)有第三種選擇。降低Outlook中的安全性。我已經這樣做了,而且我不再使用這些彈出窗口(我正在使用Off-2010) –

+0

@SiddharthRout只要您知道這不是建議的。 – JimmyPena

+0

@JP:在共享電腦上是絕對不推薦的。但在我的個人筆記本電腦,其中一個人有訪問+它是完全保護與最新AV軟件+我小心不要打開任何未知的宏文件,我沒有看到任何問題:) –

0

您不必使用Outlook發送電子郵件。正如你所問,CDO的工作原理沒有使用Outlook。

這裏有一些代碼讓你開始。

Public Sub SendEmail(Subject As String, Body As String, ToPerson as String) 

Dim iCfg As Object 
Dim iMsg As Object 

Set iCfg = CreateObject("CDO.Configuration") 
Set iMsg = CreateObject("CDO.Message") 

With iCfg.Fields 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email-account" 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = "[email protected]" 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True 
    .Update 
End With 

With iMsg 
    .Configuration = iCfg 
    .Subject = Subject 
    .TextBody = Body 
    .To = ToPerson 
    .Send 
End With 

Set iMsg = Nothing 
Set iCfg = Nothing 

End Sub 
+2

您應該引用此代碼的來源。 – brettdj

+0

我不再有原始來源。這是我在其中一個項目中使用的代碼。 –

+0

我也使用這個代碼。這裏是[來源](http://www.rondebruin.nl/cdo.htm)。 – deusxmach1na

相關問題