我需要發送帶有附件和簽名的Outlook電子郵件。發送帶有附件和簽名的Outlook電子郵件
以下是我的VBA代碼。
我收到錯誤「Transport failedtoconnect server」。看來我沒有給出正確的SMTP服務器地址。
此外,我需要寫公司的標誌簽名。
Sub Outlook()
Dim Mail_Object As Object
Dim Config As Object
Dim SMTP_Config As Variant
Dim Email_Subject, Email_Send_From, Email_Send_To, Email_Cc, Email_Body As String
Dim Current_date As Date
Current_date = DateValue(Now)
Email_Subject = "Daily Pending IMs Report (" & Current_date & ")"
Email_Send_From = "[email protected]"
Email_Send_To = "[email protected]"
'Email_Cc = "[email protected]"
Email_Body = "Dear All," & vbCrLf & "" & vbCrLf & "Kindly find Daily Pending IMs Report in the attached files."
Set Mail_Object = CreateObject("CDO.Message")
On Error GoTo debugs
Set Config = CreateObject("CDO.Configuration")
Config.Load -1
Set SMTP_Config = Config.Fields
With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "nnnnnn"
.Update
End With
With Mail_Object
Set .Configuration = Config
End With
'enter code here
Mail_Object.Subject = Email_Subject
Mail_Object.From = Email_Send_From
Mail_Object.To = Email_Send_To
Mail_Object.TextBody = Email_Body
Mail_Object.cc = Email_Cc
'Mail_Object.AddAttachment "C:\Pending IMs\Pending IMs.pdf"
Mail_Object.Send
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
這不是vb.net是VBscript嗎?請相應地編輯您的標籤。謝謝 –
編輯................. – Muneeb
謝謝。有些人 - 像我一樣。標記標記他們不太瞭解被忽略。其他人只搜索看他們知道的標籤的問題。所以正確的標記可能會幫助你得到答案。 –