Hello.
I use the following code to automatically send e-mails from a database using the smtp method:
The e-mail variable is in this form: maf@myemail.com; bfe@myemail.com; tyr@myemail.com
This code works really well with one exception; when one of the e-mails is not recognized by the server it returns an error and it does not send the e-mail.
Error: "The server rejected one or more recipient addresses. The server response was: 550 No such recipient "
What I'd like to do is for the code to be able to figure out which e-mail address is creating the problem and resend the message to all but that e-mail. A message box needs to be displayed to warn the user about that e-mail not working.
What do you suggest?
mafhobb
I use the following code to automatically send e-mails from a database using the smtp method:
Code:
Public Function SendsmtpEmail(txtRecipient As String, txtSender As String, txtsubject As String, txtbody As String) As String
On Error GoTo errorhandler
Dim mail
Dim sName As String
Set mail = Nothing
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Const cdoSendUsingPort = 2
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xx.xx.x.xx"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With
' Apply the settings to the message.
With iMsg
Set .Configuration = iConf
.to = txtRecipient
.From = txtSender
.Subject = txtsubject
.HTMLBody = txtbody
DoEvents
.Send
End With
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Exit Function
The e-mail variable is in this form: maf@myemail.com; bfe@myemail.com; tyr@myemail.com
This code works really well with one exception; when one of the e-mails is not recognized by the server it returns an error and it does not send the e-mail.
Error: "The server rejected one or more recipient addresses. The server response was: 550 No such recipient "
What I'd like to do is for the code to be able to figure out which e-mail address is creating the problem and resend the message to all but that e-mail. A message box needs to be displayed to warn the user about that e-mail not working.
What do you suggest?
mafhobb