troubleshooting Question

ASP.net Emailing programmatically

Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on
HTMLASP.NETVisual Basic.NET
3 Comments1 Solution46 ViewsLast Modified:
Hi. I have the following information in my ASP.net web config file for sending emails using the VB.net code further down. For some reason this has just sopped working. Is there better code that I can use? Is there somewhere that I could perhaps test that these settings will in fact send an email?
Thanks

    <smtp from="noreply@thexxxx.com">
        <network host="mail.thexxx.com" port="587" userName="noreply@thexxx.com" password="xx" />
      </smtp>

    Public Function oSendMailMessage(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
        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()
            ' Send the mail message
            mSmtpClient.Send(mMailMessage)
            oSendMailMessage = "Email Success!"
        Catch ex As Exception
            oSendMailMessage = "Email Not Sent! " & ex.Message
        End Try
    End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros