Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried almost hundreds of codes on this but smtp server 5.5.1.error always there. it requires user authentication so please tell me how to authenticate user in smtp. my code is given below:

VB
Imports System.Net.Mail
Imports System.Net

Partial Class Contact
    Inherits System.Web.UI.Page
    Public Property Credentials As ICredentialsByHost

    Protected Sub ok_Click(sender As Object, e As EventArgs) Handles ok.Click

            Dim fromaddr As String = txtemail.Text
            Dim toaddr As String = "Email Address"
        Dim password As String = "Password"

            Dim msg As MailMessage
            Dim smtp As SmtpClient
            Dim nc As NetworkCredential
            msg = New MailMessage()

            msg.Subject = lname.Text
            msg.From = New MailAddress(fromaddr)
            msg.Body = txtquery.Text
            msg.To.Add(New MailAddress(txtemail.Text))
            smtp = New SmtpClient()
            smtp.Credentials = New System.Net.NetworkCredential(fromaddr, password)
        smtp.Host = "smtp.gmail.com"
            smtp.Port = 587
        smtp.UseDefaultCredentials = False
            smtp.EnableSsl = True
        smtp.Send(msg)
        Try
            smtp.Send(msg)
            MsgBox("email sent")
        Catch ex As Exception
            Response.Write("<script>alert('" + ex.ToString() + "');</script>")
        End Try
    End Sub

End Class
Posted
Updated 19-Oct-15 20:59pm
v2
Comments
F-ES Sitecore 20-Oct-15 4:20am    
This question is asked daily, please do your own basic research before asking a question such as using google.

http://forums.asp.net/post/5825785.aspx
Member 12059614 20-Oct-15 8:54am    
Sir I did so many things I have not to run my company I have a college project and that's why I am using SMTP server rather than hosting server I googled so many things and still there is a problem that's why I asked the question.
F-ES Sitecore 20-Oct-15 8:56am    
Your college will probably have am smtp server you can use, ask the sysadmins.

1 solution

Solution Refer : http://how2doinvbdotnet.blogspot.ae/2015/06/send-email-from-gmail-with-smtp.html
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900