Please go through my code and tell me where i am making mistake.
Dim dConn As New OleDbConnection
Dim dContactsDA As New OleDbDataAdapter
Dim dReader As OleDbDataReader
Dim s As String()
dContactsDA.SelectCommand =New OleDbCommand("SELECT * FROM kishan", dConn)
dContactsDA.SelectCommand.CommandType = CommandType.Text
dReader = dContactsDA.SelectCommand.ExecuteReader
Send("smtp.gmail.com", "firstname.lastname@example.org")' dummy email address End Sub
mail.From =New MailAddress("email@example.com") 'set the content
mail.Subject ="This is an email"
mail.Body ="this is the body content of the email."
client.Credentials =New Net.NetworkCredential("firstname.lastname@example.org", "********") 'client.Port = 465
client.Timeout = 1000 * 60 * 10AddHandler client.SendCompleted, AddressOf client_SendCompleted
client.SendAsync(mail, txt)Return True Catch ex As Exception
txtLog.AppendText(e.Error.ToString & ControlChars.CrLf)
txtLog.AppendText(d & ControlChars.CrLf)
Application.DoEvents()End While End Sub
After sending 1 to 3 emails, i receive the following errors and then my program stop sending email
"System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.Sockets.SocketException: An invalid argument was supplied
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of inner exception stack trace ---"
I've done lots of search on net in many search engines and many forums but i am not able to figure it out the reason of error. I've changed my coding in many ways but still all in-vain. Kindly help me with the error.
KishanThursday, December 20, 2007 1:43 PM
Firstly, I'd like to say that it is a pity nobody has gotten back to you in regard to this.
Now I have had a similiar problem, but I think in a different environment. My environment is ASP.NET on IIS.
I think yours is Winforms or Console.
What I have discovered is that the error is occurring because the Smtp server:"smtp.gmail.com", in your case cannot be connected. But you probably knew that.
I don't know whether this will help you but here is what I did in IIS
In the IIS "Default SMTP Virtual Server", Properties -> Delivery tab->Advanced there is a field for "Smart Host"
I set that field to my remote Smtp server:"smtp.gmail.com", in your case.
Then in the config file I changed the host="127.0.0.1" under Network. As in the section below
<smtp deliveryMethod="Network" from="MyAddress@MyServer.com.au">
<network host="127.0.0.1" port="25" userName="MyAddress@MyServer.com.au" password="MyPassword" defaultCredentials="true"/>
I suspect that you are not using IIS or ASP.NET. But you can get your Network Administrator to help you.
He may be able to route your traffic through another SMTP server. You can then address that local SMTP server and allow it to re-route your smtp.gmail.com traffic.
Also get him to read up on the Help that goes with the IIS dialog, IIS "Default SMTP Virtual Server", Properties -> Delivery tab. It may give him more hints. especially the bit on Smart Host.
RegardsMonday, May 12, 2008 5:59 AM