0
我有一個Access腳本,它使用smtp證書成功發送繞過Outlook的電子郵件。在VB中從Outlook中提取SMTP地址
但是我希望我的腳本能夠自動檢測每個使用此用戶的smtp服務器,而不必將其硬編碼到腳本中或手動輸入。有人能幫忙嗎?
編輯:
這是我正在使用的當前代碼。我不想使用任何第三方工具來達到此目的。
Public Sub send_email()
Dim iCfg As Object
Dim iMsg As Object
Dim dtm As Date
Dim dtt As Date
dtm = DateValue(Now)
dtt = TimeValue(Now)
Set iCfg = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")
'SMTP Server settings with username and password fields
With iCfg.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "NHS-PCLI- MBC013.AD1.NET"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = LabelFrom.Caption
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = LabelPass.Caption
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = LabelFrom.Caption
.Update
End With
'Form the email with user input settings and date with time as set by system
With iMsg
.Configuration = iCfg
.From = LabelFrom.Caption
.Subject = LabelSubject.Caption & " <DB Form Sent " & dtm & " " & dtt & ">"
.To = LabelTo.Caption
.TextBody = LabelBody.Caption
.Send
MsgBox ("Email sent")
fldBody.Value = ""
Password.Value = ""
fldTo.Value = ""
fldFrom.Value = ""
fldSubject.Value = ""
LabelBody.Caption = ""
LabelTo.Caption = ""
LabelFrom.Caption = ""
LabelSubject.Caption = ""
LabelPass.Caption = ""
End With
Set iMsg = Nothing
Set iCfg = Nothing
End Sub
此問題似乎是無關緊要的,因爲它缺乏足夠的信息來診斷問題。更詳細地描述你的問題,或者在問題本身中包含一個簡單的例子。 – equisde
我們能否看到您現有的代碼並獲取更多信息?只是猜測,但認爲這將是棘手。如果您要讓用戶提供「發件人」地址,那麼您必須執行Mxlookup來驗證SMTP,並讓他們向該服務器提供憑據。 –