ASP.NET
--
Questions
--
Followers
Top Experts
ASP.net Step Into Error when emailing
I am running the following code to test why emails are not going through. When I step into the line "     mSmtpClient.Send(mMailMess age)" I get the error shown in the image
  Protected Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
    Dim oEmailResult As String = oSendMailHere("abc@abc.co. za", "abc@yahoo.com", "abc@yahoo.com", "", "New Test Email Header", "This is a test email", True)
    If oEmailResult = "Email Success!" Then
      Me.Label11.Text = "Email was sent"
    Else
      Me.Label11.Text = "##NOT SENT##"
    End If
  End Sub
  Function oSendMailHere(ByVal from As String, ByVal recepient As String, ByVal bcc As String,
                 ByVal cc As String, ByVal subject As String, ByVal body As String,
                 ByVal blnUseHTML As Boolean) As String
    Dim oException As String
    Dim oInnerException As String
    Dim oStackTrace As String
    Dim oError As String
    Me.lblEmailError.Text = ""
    Try
      ' Instantiate a new instance of MailMessage
      Dim mMailMessage As New MailMessage()
      ' Set the sender address of the mail message
      mMailMessage.From = New MailAddress(from)
      ' Set the recepient address of the mail message
      mMailMessage.To.Add(New MailAddress(recepient))
      ' Check if the bcc value is nothing or an empty string
      If Not bcc Is Nothing And bcc <> String.Empty Then
        ' Set the Bcc address of the mail message
        mMailMessage.Bcc.Add(New MailAddress(bcc))
      End If
      ' Check if the cc value is nothing or an empty value
      If Not cc Is Nothing And cc <> String.Empty Then
        ' Set the CC address of the mail message
        mMailMessage.CC.Add(New MailAddress(cc))
      End If
      ' Set the subject of the mail message
      mMailMessage.Subject = subject
      ' Set the body of the mail message
      mMailMessage.Body = body
      ' Set the format of the mail message body as HTML
      If blnUseHTML = True Then
        mMailMessage.IsBodyHtml = True
      Else
        mMailMessage.IsBodyHtml = False
      End If
      ' Set the priority of the mail message to normal
      mMailMessage.Priority = MailPriority.Normal
      ' Instantiate a new instance of SmtpClient
      Dim mSmtpClient As New SmtpClient()
      Stop
      ' Send the mail message
      mSmtpClient.Send(mMailMess age)
      oSendMailHere = "Email Success!"
      Stop
    Catch ex As Exception
      Stop
      oException = ex.Message
      oInnerException = ex.InnerException.ToString
      oStackTrace = ex.StackTrace
      oError = "Email Not Sent! " & oException & " Inner Exception " & oInnerException & " Stack Trace " & oStackTrace
      Stop
      Me.lblEmailError.Text = oError
      oSendMailHere = "Email Not Sent! " & oError
    End Try
  End Function
  Protected Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
    Dim oEmailResult As String = oSendMailHere("abc@abc.co.
    If oEmailResult = "Email Success!" Then
      Me.Label11.Text = "Email was sent"
    Else
      Me.Label11.Text = "##NOT SENT##"
    End If
  End Sub
  Function oSendMailHere(ByVal from As String, ByVal recepient As String, ByVal bcc As String,
                 ByVal cc As String, ByVal subject As String, ByVal body As String,
                 ByVal blnUseHTML As Boolean) As String
    Dim oException As String
    Dim oInnerException As String
    Dim oStackTrace As String
    Dim oError As String
    Me.lblEmailError.Text = ""
    Try
      ' Instantiate a new instance of MailMessage
      Dim mMailMessage As New MailMessage()
      ' Set the sender address of the mail message
      mMailMessage.From = New MailAddress(from)
      ' Set the recepient address of the mail message
      mMailMessage.To.Add(New MailAddress(recepient))
      ' Check if the bcc value is nothing or an empty string
      If Not bcc Is Nothing And bcc <> String.Empty Then
        ' Set the Bcc address of the mail message
        mMailMessage.Bcc.Add(New MailAddress(bcc))
      End If
      ' Check if the cc value is nothing or an empty value
      If Not cc Is Nothing And cc <> String.Empty Then
        ' Set the CC address of the mail message
        mMailMessage.CC.Add(New MailAddress(cc))
      End If
      ' Set the subject of the mail message
      mMailMessage.Subject = subject
      ' Set the body of the mail message
      mMailMessage.Body = body
      ' Set the format of the mail message body as HTML
      If blnUseHTML = True Then
        mMailMessage.IsBodyHtml = True
      Else
        mMailMessage.IsBodyHtml = False
      End If
      ' Set the priority of the mail message to normal
      mMailMessage.Priority = MailPriority.Normal
      ' Instantiate a new instance of SmtpClient
      Dim mSmtpClient As New SmtpClient()
      Stop
      ' Send the mail message
      mSmtpClient.Send(mMailMess
      oSendMailHere = "Email Success!"
      Stop
    Catch ex As Exception
      Stop
      oException = ex.Message
      oInnerException = ex.InnerException.ToString
      oStackTrace = ex.StackTrace
      oError = "Email Not Sent! " & oException & " Inner Exception " & oInnerException & " Stack Trace " & oStackTrace
      Stop
      Me.lblEmailError.Text = oError
      oSendMailHere = "Email Not Sent! " & oError
    End Try
  End Function
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Thanks Chinmay. This code worked fine before. I am not sure what to change
Where is your mail server hosted? Can you make a quick check that can confirm you are using right mailboxes? Maybe they changed a port or some other setting?
PS: I realized you are using .Net's SMTP class not MailKit.
PS: I realized you are using .Net's SMTP class not MailKit.
Thanks Chinmay.I tried smtp settings from an older project and that dis the trick






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Glad it worked out well. I still have a recommendation, that you move to MailKit if possible :)
ASP.NET
--
Questions
--
Followers
Top Experts
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications