我有一个Access脚本,可以使用smtp凭据绕过Outlook成功发送电子邮件。
但是我希望我的脚本能够自动检测每个使用它的用户的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