【发布时间】:2014-03-03 17:34:24
【问题描述】:
我有一个使用 smtp 凭据绕过 Outlook 成功发送电子邮件的 Access 脚本。
但是,我希望我的脚本自动检测每个使用它的用户的 smtp 服务器,而不必将其硬编码到脚本中或手动输入。有人可以帮忙吗?
编辑:
这是我正在使用的当前代码。我不想使用任何第 3 方工具来实现这一目标。
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
【问题讨论】:
-
这个问题似乎离题了,因为它缺乏足够的信息来诊断问题。更详细地描述您的问题或在问题本身中包含一个最小示例。
-
我们可以查看您现有的代码并获得更多信息吗?只是猜测,但认为这会很棘手。如果您让用户提供“发件人”地址,那么您必须执行 Mxlookup 来验证 SMTP,并让他们提供该服务器的凭据。
标签: vb.net ms-access outlook smtp