i want to send an email with my gmail account but i have this error and the email doas'nt sent !
http://up.dev-point.com/uploads1/a75d55e308e91.png
My code is :
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 587)
SmtpServer.Credentials = New Net.NetworkCredential("ihab#gmail.com", "pass")
Dim mail As New MailMessage("ihab#gmail.com", "ihab#gmail.com", "New", "txt")
SmtpServer.Send(mail)
End Sub
Please see this case, I think you need to make sure SSL is enabled and possibly modify account settings for smtp access.
Sending email through Gmail SMTP server with C#
If you need assistance converting the C# code to vb.net let me know
Related
I am using Gmail setting for sending mail, i got an error like "Failure sending mail." and InnerException as "Unable to read data from the transport connection: net_io_connectionclosed."
My project frame work is .Net 4.8 ,
Programming Language vb ,
OS is Windows 11 .
Anything need to change in Gmail account setting ?
What I have tried:
Imports System.Net
Imports System.Net.Mail
Public Class Form1
Public Shared Function ServerCertificateValidationCallback(ByVal sender As Object, ByVal cert As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim Mail As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
Mail.From = New MailAddress("aravind#gmail.com", "Aravind")
Mail.To.Add("aravind1#gmail.com")
Mail.IsBodyHtml = True
Mail.Subject = "Hai Testing Mail"
smtp = New SmtpClient("smtp.gmail.com", "587")
smtp.EnableSsl = True
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential("aravind#gmail.com", "xxxxxxxxxxx")
Dim userstate As Object = Mail
System.Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf ServerCertificateValidationCallback
smtp.Send(Mail)
Catch ex As Exception
MessageBox.Show(ex.InnerException.ToString)
MessageBox.Show(ex.Message.ToString)
End Try
End Sub
End Class
Note i tried with 465 and 25 as ports,still same problem.
1.Port 465 - error as "Failure sending mail." and InnerException as "Unable to read data from the transport connection: net_io_connectionclosed."
2.Port 25 - error as "Failure sending mail." and InnerException as "Unable to connect to the remote server"
And one more thing i tried with another gmail account with enabled 2 step versification and with app password working fine, i mean from my another account can send mail.
try to use port 465 port or 25 port instead of 587,hope this will solve your issue if further details you want then please refer to this link
https://kinsta.com/blog/gmail-smtp-server/
I'm trying to send a message using EWS Managed API, and I need to confirm message was sent and register some info (ex. the date & time it was sent). However, I get an exception as shown below. My question is: how can I retrieve the EmailMessage object for the sent message, after it was sent?
Thank you very much!
Private Sub NovaMensagemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NovaMensagemToolStripMenuItem.Click
Dim em As New EmailMessage(serviceClient.Service)
em.Subject = "Test"
em.Body = "This is a test."
em.ToRecipients.Add("mytestmail#test.com")
em.SendAndSaveCopy(WellKnownFolderName.SentItems)
em.Load() 'Exception: System.InvalidOperationException: This operation can't be performed because this service object doesn't have an Id.
MsgBox(em.DateTimeSent)
End Sub
Apparently, all it takes is to save a draft before sending:
Private Sub NovaMensagemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NovaMensagemToolStripMenuItem.Click
Dim em As New EmailMessage(serviceClient.Service)
em.Subject = "Test"
em.Body = "This is a test."
em.ToRecipients.Add("mytestmail#test.com")
em.Save(WellKnownFolderName.Drafts) '<--- added this
em.SendAndSaveCopy(WellKnownFolderName.SentItems)
em.Load() 'no exception now
MsgBox(em.DateTimeSent)
End Sub
So, I'm trying to send an email using the code below, and I get this error:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated.
I've already allowed unsecure applications to send me emails and turned off my 2-Step Verification on my gmail, and of course I replaced Net.NetworkCredential("myvalidemail#gmail.com", "mypassword") with my real email and password, but I still get that error.
I am running the program through VB debug, but that shouldn't matter.
Private Sub SendBtn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SendBtn.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.UseDefaultCredentials = False
SmtpServer.Credentials = New _
Net.NetworkCredential("myvalidemail#gmail.com", "mypassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("myvalidemail#gmail.com")
mail.To.Add("myvalidemail#gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
mail.Priority = MailPriority.High
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
The exception says that SMTP server requires a secure connection. Try enabling the SSL
SmtpServer.EnableSsl = true;
"client was not authenticated"
Just a thought: do you use Google Two Factor Authorization?
I am trying to send SMTP email from my vb.net form application. When applying this code, I get the error below. What am I doing wrong?
Code:
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("myemail#gmail.com", "mypassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("myemail#gmail.com")
mail.To.Add("sendto#hotmail.co.uk")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Error:
System.Net.Mail.SmtpException: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.7.0 Must issue a STARTTLS command first
Check if the login and password are correct;
Use SmtpServer.EnableSsl = true;
Gmail has disabled access using credentials (user and password) by default, you need go to this page: https://www.google.com/settings/security/lesssecureapps and "Enable Less Secure Apps", this means: "Enable login by apps using user and password". More details here: https://support.google.com/accounts/answer/6010255
See if this helps; Add
SmtpServer.EnableSSL= true
I know this was last year but I thought I should publish the answer as five minutes ago I had the same issue.
Basically your log in credentials are incorrect and need changing.
Also thanks for the previous answer has that piece of code allows me to send emails over SSL encryption (I Hope LOL).
I want to get current internet ip address in vb.net. I don't want localhost ip address. like as (http://www.ipchicken.com/ website return ip address)
I understand what you are wanting is the IP address as you appear on the internet and NOT your internal network IP. I've got some code somewhere I'll dig out for you but it basically comprised of this (from memory):
Create a WebRequest and WebResponse object
Request a webpage (using WebRequest) that shows your IP (such as IP Chicken) and capture the response in the WebResponse object
Parse the response using regular expressions to collect your IP
Like I say I'll try and dig out the code but this should be more than enough information for you to work on :-)
Something like this should get your current public IP.
Public Class Form1
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
End Sub
Public WithEvents wb As New WebBrowser
'before using wb add
'AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
Private Sub GetPubIP()
Try
'the site returns a string like "Current IP Address: 69.59.196.211"
wb.Navigate(New Uri("http://checkip.dyndns.org"))
Catch ex As Exception
'add error checking
End Try
End Sub
Private Sub wb_DocumentCompleted(ByVal sender As Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
'parse the reply
Dim parts() As String = wb.Document.Body.InnerText.Split(":"c)
Debug.WriteLine(parts(1).Trim)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
GetPubIP()
End Sub
End Class
Here's what you're looking for. I wrote a simple PHP script to return the IP address when called, then wrote this VB.Net code to call it at any time:
Public Function jnWhatIsMyExternalIP() As String
Dim strURL As String = "http://www.mycompanywebsite/jnNetworkTools/jnCheckIP.php"
Dim Request As System.Net.WebRequest = System.Net.WebRequest.Create(strURL)
Dim Response As System.Net.WebResponse = Request.GetResponse()
Dim Reader As New System.IO.StreamReader(Response.GetResponseStream())
Dim strMyIP As String = Reader.ReadToEnd()
Return strMyIP
End Function
Here's the PHP code that is in jnCheckIP.php:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
Calling the VB.Net function causes the users machine to call the PHP script on your server which then returns the users IP address.
You can know real ip address only if your host (pc) have static internet ip address, not like 194.x.x.x or 10.x.x.x and other http://en.wikipedia.org/wiki/Private_network
Otherwise try to send http request to service like www.ipchicken.com or other http://www.google.ru/search?hl=en&q=my+ip+address to know your ip address
This should do the trick:
http://www.vbdotnetheaven.com/UploadFile/prvn_131971/ipvb11162005073000AM/ipvb.aspx
Function GetIP() As String
Dim IP As New WebClient
Return IP.DownloadString("http://icanhazip.com/")
End Function