Click here to Skip to main content
15,868,006 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
When i click on SEND button the email is not sent. error occurs . please help me to fix it.

VB
Imports System.Net.Mail


Public Class Form1


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Try
            Dim Mail As New MailMessage

            Mail.Subject = "test email"
            Mail.To.Add(TextBox2.Text)
            Mail.From = New MailAddress(TextBox1.Text)
            Mail.Body = TextBox3.Text

            Dim SMTP As New SmtpClient("smtp.gmail.com")


            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential("username", "password")
            SMTP.Port = "587"
            SMTP.Send(Mail)

        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try
    End Sub
End Class


ERROR
THE SMPT SERVER REQUIRES SECURE CONNECTION OR THE CLIENT WAS NOT AUTHENTICATED

[edit]Code block added[/edit]
Posted
Updated 15-Apr-13 0:39am
v2
Comments
Member 2707515 15-Apr-13 5:52am    
port no = 25
AP900 15-Apr-13 6:12am    
this port no is also not working. how to check available ports or how many ports are there.
JMAM 16-Apr-13 8:22am    
I think Port 587 is correct i have tried this before. Be sure to disable your 2 steps gmail account verification.

If it is enabled, Gmail will send you security code either to your mobile or email account then you have to enter that dynamic security code every attempts

 
Share this answer
 
Comments
AP900 15-Apr-13 5:51am    
No its not working !
VB
Dim smtp As New SmtpClient
        With smtp
            .Host = "smtp.gmail.com"
            .Port = "25"
            .EnableSsl = True
            .Credentials = New System.Net.NetworkCredential("test@gmail.com", "test@123")
            .Timeout = 0
            Try
                .Send(message)
                Return True
            Catch ex As Exception
                Return False
            End Try
        End With


[edit]Code block added[/edit]
 
Share this answer
 
v3
Comments
AP900 15-Apr-13 6:09am    
Still not Working......please suggest another solution..
Member 2707515 15-Apr-13 6:35am    
dude its working my code still running good c its only for gmail id
Member 2707515 15-Apr-13 6:47am    
dude i use port=587 its working on both port it means some thing is missing in ur system can u email me ur code with whole project i will test ur code in my system on navaid.farooqui99@gmail.com
AP900 15-Apr-13 9:36am    
ok . BUT i use Visual Studio 2012....
I think Port 587 is correct i have tried this before. Be sure to disable your 2 steps gmail account verification.

If it is enabled, Gmail will send you security code either to your mobile or email account then you have to enter that dynamic security code every attempts

BTW here is my code.

VB
Dim mail As New MailMessage
mail.Subject = txtsubject.Text
mail.To.Add("xxx@yahoo.com")
mail.From = New MailAddress("yyyyy@gmail.com")
mail.Body = "Hello World"

Dim smtp As New SmtpClient("smtp.gmail.com")
smtp.EnableSsl = True
smtp.Credentials = New                                              System.Net.NetworkCredential("yyyyy@gmail.com", "xxxxxxxxxxx")
smtp.Port = "587" ' for gamil.
smtp.Send(mail)
 
Share this answer
 
Comments
AP900 16-Apr-13 23:40pm    
error occurs that " SMTP server requires secure connection......"
JMAM 16-Apr-13 23:51pm    
Try to use the gmail account your are using right now. Just login on google mail then check if system ask you to enter some security codes then that is the error you are getting, probably gmail is asking for 2 steps verification.

Another advice is for you to make a new google email for testing only. Send us the exact email and password so we can test it here.
AP900 16-Apr-13 23:54pm    
2 step verification is disabled on my gmail account.but error still occurs.
JMAM 16-Apr-13 23:57pm    
The best thing you can do is create a new gmail account and share login information here, Just make sure the account you will share is not personal and for testing only.

In that way we can see actual errors on our own
AP900 16-Apr-13 23:57pm    
i tried on yahoo but error occurs that "email sending failed".....
port no=27

is IIS needed

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