How to send email in asp.net vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahul2310
    New Member
    • Oct 2013
    • 62

    How to send email in asp.net vb.net

    i Am using below code in vb.net to send email using smtp

    Code:
                    Dim strmsgbody As String
                    strmsgbody = "Your Login Deatils For SESS IS" & vbNewLine & "User Name:'" & TextBox1.Text & "'" & vbNewLine & "Password:" & TextBox2.Text & " '"
                    Using mm As New MailMessage("rahulsankhe2310@gmail.com", txtforpassempemail.Text)
                        mm.Subject = "Password Recovery Of Schindler Employee Self Service"
                        mm.Body = strmsgbody
    
                        mm.IsBodyHtml = False
                        Dim smtp As New SmtpClient()
                        smtp.Host = "smtp.gmail.com"
                        smtp.EnableSsl = True
                        Dim NetworkCred As New NetworkCredential("senderemail.text", "senderpassword")
                        smtp.UseDefaultCredentials = True
                        smtp.Credentials = NetworkCred
                        smtp.Port = 587
                        smtp.Send(mm)
                        ClientScript.RegisterStartupScript(Me.GetType, "alert", "alert('Email sent.');", True)
                    End Using
    
                    Response.Write("<script type='text/javascript'>alert('PASSWORD ALONG WITH LOGIN DETAILS SEND TO PROVIDED EMAIL ADDRESS');</script>")
                    txtforpassempcode.Text = ""
                    txtforpassempemail.Text = ""
                    Response.Redirect("SESSLogin.aspx", False)
    The code works well for gmail but when i change smtp name and port number of my organization smtp server anme and port 25 it gives
    error "sending email failed"

    Please Help
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You need to configure your MailMessage with settings that will work for the server you are connected to.

    I suggest that you investigate your mail server to determine if it uses SSL, what port etc.


    -Frinny

    Comment

    Working...