Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMTPClient

Status
Not open for further replies.

UKmedia

Programmer
Nov 2, 2002
90
Afternoon,

I am finding it difficult to send an email via a asp.net project I am working on. I have posted the code I am using below

Code:
        Dim mMailServer As String
        Dim mTo As String
        Dim mFrom As String
        Dim mMsg As String
        Dim mSubject As String
        Dim mPort As Integer

        mTo = Trim("richard.thatcher@gmail.com")
        mFrom = Session("Email")
        mSubject = Trim(txtSubject.Text)
        mMsg = Trim(txtMessage.Text)
        mMailServer = ("no-auth.no-ip.com")
        mPort = (25)

        Try

            Dim message As New MailMessage(mFrom, mTo)
            Dim SmtpClient As New SmtpClient(mMailServer)
            message.Subject = mSubject
            message.Body = mMsg
            message.IsBodyHtml = False
            SmtpClient.Credentials = New System.Net.NetworkCredential("sean@gardiff.com", "654a32")
            SmtpClient.Send(message)

            MessageBox("The mail message has been sent to " & mTo)

        Catch ex As FormatException

            MessageBox("Format Exception: " & ex.Message)

        Catch ex As SmtpException

            MessageBox("SMTP Exception:  " & ex.Message)

        Catch ex As Exception

            MessageBox("General Exception:  " & ex.Message)

        End Try

        lblMessage.Text = "Message Sent"

    End Sub

When it fires it is not doing anything nor given an error. Am I doing this correctly?

UKmedia productions
 
1. your using message boxes in asp.net. this doesn't work because the user will never see the server's UI. since your not doing anything with the error, you shouldn't be catching errors here anyway. let the exception climb the stack and catch at the UI, or HttpApplication Error handler (defined by you).

2. Message.To is a collection so you need to add the email address, not set it. Message.To.Add(new EmailAddress("a@b.c");

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top