Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:52:32+00:00 2026-05-24T02:52:32+00:00

hello fellow :) i am having a trouble on how can i retry sending

  • 0

hello fellow 🙂 i am having a trouble on how can i retry sending failed email recipients. i am trying to make an application in vbnet where i can send emails to multiple address.

some code snippet:

Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New Net.NetworkCredential(xInformation(0), xInformation(1))
SmtpServer.Port = CInt(xInformation(2))
SmtpServer.Host = xInformation(3) 
SmtpServer.EnableSsl = True

Dim mail As New MailMessage()
mail = New MailMessage
mail.From = New MailAddress(xInformation(4), "Display Name")
mail.CC.Add(xInformation(5))  ' i will make a loop here to add recipients
mail.Subject = xInformation(6)
mail.IsBodyHtml = True
mail.Body = xInformation(7)

SmtpServer.Send(mail)

question arises:

1.) if i have to send, for instance, email to 5 recipients, and only 
        3 emails have been successfully sent, how can i know the 
        failed email addresses?
2.) where is the failed email address stored?
3.) what exceptions are needed to trapped this error?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:52:33+00:00Added an answer on May 24, 2026 at 2:52 am

    I don’t think you can catch these exceptions in your code, the emails that do not get sent you will want to check on the smtp server there should be a mail folder within inetpub

    \\ServerName\c$\Inetpub\mailroot

    Inside of this folder you should find a folder called: BadMail and Drop please look at the contents of these. Your VB code doesn’t have access to what a valid email address might be, only that it will try to send an smtp email message, if it fails then the SMTP application handles that.

    Per your comment:

    Imports System.Net.Mail
    Imports System.Threading
    Imports System.Web.Configuration
    
    ''' <summary>
    ''' Provides a method for sending email.
    ''' </summary>
    Public NotInheritable Class Email
        Private Sub New()
        End Sub
        ''' <summary>
        ''' Constructs and sends an email message.
        ''' </summary>
        ''' <param name="fromName">The display name of the person the email is from.</param>
        ''' <param name="fromEmail">The email address of the person the email is from.</param>
        ''' <param name="subject">The subject of the email.</param>
        ''' <param name="body">The body of the email.</param>
        Public Shared Sub Send(fromName As String, fromEmail As String, subject As String, body As String)
            Dim message As New MailMessage() With { _
                Key .IsBodyHtml = False, _
                Key .From = New MailAddress(fromEmail, fromName), _
                Key .Subject = subject, _
                Key .Body = body _
            }
            message.[To].Add(WebConfigurationManager.AppSettings("mailToAddresses"))
    
            Dim originalRecipientCount As Integer = message.[To].Count
            Dim failOnAnyAddress As Boolean = Convert.ToBoolean(WebConfigurationManager.AppSettings("failOnAnyAddress"))
    
            Try
                Send(message)
            Catch generatedExceptionName As SmtpFailedRecipientException
                If message.[To].Count = originalRecipientCount Then
                    ' all recipients failed
                    Throw
                End If
    
                If failOnAnyAddress Then
                    ' some (not ALL) recipients failed
                    Throw
                End If
            End Try
        End Sub
    
        Private Shared Sub Send(message As MailMessage)
            Dim client As New SmtpClient()
    
            Try
                client.Send(message)
            Catch ex As SmtpFailedRecipientsException
                ' multiple fail
                message.[To].Clear()
    
                For Each sfrEx As SmtpFailedRecipientException In ex.InnerExceptions
                    CheckStatusAndReaddress(message, sfrEx)
                Next
    
                If message.[To].Count > 0 Then
                    ' wait 5 seconds, try a second time
                    Thread.Sleep(5000)
                    client.Send(message)
                Else
                    Throw
                End If
            Catch ex As SmtpFailedRecipientException
                ' single fail
                message.[To].Clear()
    
                CheckStatusAndReaddress(message, ex)
    
                If message.[To].Count > 0 Then
                    ' wait 5 seconds, try a second time
                    Thread.Sleep(5000)
                    client.Send(message)
                Else
                    Throw
                End If
            Finally
                message.Dispose()
            End Try
        End Sub
    
        Private Shared Sub CheckStatusAndReaddress(message As MailMessage, exception As SmtpFailedRecipientException)
            Dim statusCode As SmtpStatusCode = exception.StatusCode
    
            If statusCode = SmtpStatusCode.MailboxBusy OrElse statusCode = SmtpStatusCode.MailboxUnavailable OrElse statusCode = SmtpStatusCode.TransactionFailed Then
                message.[To].Add(exception.FailedRecipient)
            End If
        End Sub
    End Class
    

    Convert any code from C# to vb.net: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a ThreadPool implementation from this fellow: https://github.com/progschj/ThreadPool I'm having trouble
hello fellow java developers. I'm having a very strange issue. I'm trying to read
Hello fellow SO friends, I am having trouble with my syntax in adding a
hello fellow java developers. I'm having a bit of an issue here. I have
Hello fellow developers... just to make sure, I want to ask this question: How
Hello fellow developers, I am trying to achieve something in Android and I would
Hello fellow programmers, I'm using nice URLs the first time and I can't quite
Hello fellow developers! I am trying to get the build error codes from a
hello fellow programmers, I followed a tutorial at http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php to send a String encrypted
Hello Fellow stackoverflowers, I´m stuck writing a piece of code. I have application with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.