Hack Forums
[.NET] Sending mail (GMAIL) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Sending mail (GMAIL) (/showthread.php?tid=5064665)



Sending mail (GMAIL) - twobol2002 - Nov 20, 2015

Hi guys,

I need your help. My problem is that why I can't send an email to gmail? :(

Code
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("[email protected]", "password")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"

            e_mail = New MailMessage()
            e_mail.From = New MailAddress(txtFrom.Text)
            e_mail.To.Add(txtTo.Text)
            e_mail.Subject = "Email Sending"
            e_mail.IsBodyHtml = False
            e_mail.Body = txtMessage.Text
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")

        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try

    End Sub

please help.

Thanks in advance


* - Mouse❤️ - Nov 20, 2015

Probably because you don't own [email protected]. Kidding. I think there's more to be done to send through them. I know when I was making an SMTP mailer, I had to send like 4 times for the message to go through once (I don't know and never figured out why.)


* - SIM-2618262 - Nov 20, 2015

(Nov 20, 2015 11:55 AM)twobol2002 Wrote:  Hi guys,

I need your help. My problem is that why I can't send an email to gmail? :(

Code
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("[email protected]", "password")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"

            e_mail = New MailMessage()
            e_mail.From = New MailAddress(txtFrom.Text)
            e_mail.To.Add(txtTo.Text)
            e_mail.Subject = "Email Sending"
            e_mail.IsBodyHtml = False
            e_mail.Body = txtMessage.Text
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")

        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try

    End Sub

please help.

Thanks in advance
i don't know if this code can help you, it is a bit hard to know what is wrong? you got a error or something? i remember i had something simular in the past and this is the code that only worked to me. anyways you need to turn off some security on ur gmail to make it work. Hope it helps

Dim mymailmessage As New MailMessage()
Try
mymailmessage.From = New MailAddress("[email protected]")
mymailmessage.To.Add("[email protected]")
mymailmessage.Subject = ""
mymailmessage.Body = ": "
Dim SMPT As New SmtpClient("smtp.gmail.com")
SMPT.Port = 587
SMPT.EnableSsl = True
SMPT.Credentials = New System.Net.NetworkCredential("[email protected]", "password")
SMPT.Send(mymailmessage)




Catch ex As Exception

End Try


* - Mouse❤️ - Nov 20, 2015

rednas, your message did not contain anything. You just copy pasted a quote.


* - twobol2002 - Nov 20, 2015

it says:

"The SMTP server requires a secure connection or the client was not authenticated."


* - SIM-2618262 - Nov 20, 2015

(Nov 20, 2015 12:09 PM)twobol2002 Wrote:  it says:

"The SMTP server requires a secure connection or the client was not authenticated."
you tried the code i posted? anyways you have to go to security in ur gmail and change the security to low or something to make it possible for ur application to access it.


(Nov 20, 2015 12:09 PM)twobol2002 Wrote:  it says:

"The SMTP server requires a secure connection or the client was not authenticated."
and i think this error mean that it has something with the security with ur gmail todo. so nothing should be wrong with the code. so just change the security and it should work:)


* - nathan72389 - Nov 20, 2015

you have to allow un secure apps through your email account.
its what almost every email carrier is doing now.


* - twobol2002 - Nov 20, 2015

thanks guys for your help... i got it working by changing the settings in my gmail.... :)