Smtp error when sending mail.

drew4663

Well-known member
Joined
May 3, 2007
Messages
62
Programming Experience
1-3
I keep getting a message and I am not sure why. I don't see anything worng with this code. When I fill in all the fields and send the e-mail it says that it cannot send the e-mail. Exact error - Failure sending mail. SmtpException was unhandled. smtp.Send(message1) End error!


VB.NET:
Dim tech As String
        Dim tech1 As String
        tech1 = txtemailto1.Text
        Dim tech2 As String
        tech2 = txtemailto2.Text
        Dim tech3 As String
        tech3 = txtemailto3.Text
        Dim tech4 As String
        tech4 = txtemailto4.Text
        Dim tech5 As String
        tech5 = txtemailto5.Text
        Dim tech6 As String
        tech6 = txtemailto6.Text
        Dim tech7 As String
        tech7 = txtemailto7.Text
        Dim tech8 As String
        tech8 = txtemailto8.Text
        Dim tech9 As String
        tech9 = txtemailto9.Text
        Dim tech10 As String
        tech10 = txtemailto10.Text
        Dim tech11 As String
        tech11 = txtemailto11.Text
        Dim tech12 As String
        tech12 = txtemailto12.Text
        Dim tech13 As String
        tech13 = txtemailto13.Text

        Dim issue As String
        issue = IssueTextBox.Text

        Dim tasknumber As String
        tasknumber = WorkOrderIDTextBox.Text

        tech = tech1 + tech2 + tech3 + tech4 + tech5 + tech6 + tech7 + tech8 + tech9 + tech10 + tech11 + tech12 + tech13

        Dim message1 As New System.Net.Mail.MailMessage()
        message1.To.Add(tech)
        message1.Subject = tasknumber
        message1.From = New System.Net.Mail.MailAddress("XXXXX@XXXXXXXX.org")
        message1.Body = issue
        Dim smtp As New System.Net.Mail.SmtpClient("XXX.XX.XX.X")
        smtp.Send(message1)

Any help or insight would be appreciated. Thank you.
 
tech = tech1 + tech2 + tech3 + tech4 + tech5 + tech6 + tech7 + tech8 + tech9 + tech10 + tech11 + tech12 + tech13

You shouldn't do this - I'd use To.Add, for example:

Message1.To.Add("james@invisionsoft.co.uk")
Message1.To.Add(tech1)
Message1.To.Add(tech2)

...

VB.NET:
Dim smtp As New System.Net.Mail.SmtpClient("XXX.XX.XX.X")
I know you've blanked it out for a reason but this is probably the problem. SMTP is very picky and you need to get the right settings. This may just be setting it to use SSL or it may even require you to give it a credential. I have an excellent sample that works for Google Mail from my site:

VB.NET:
Dim theMessage As New MailMessage("sender@domain.com", "receiver@domain.com", "Subject", "Message Text")
        Dim theSender As New SmtpClient("smtp.gmail.com", 587)
        Dim theCredential As New Net.NetworkCredential("GmailAccountUsername@gmail.com", "GmailAccountPassword")
        theSender.EnableSsl = True
        theSender.Credentials = theCredential
        theSender.Send(theMessage)

- James
 
Hello Invisionsoft,

Thanks for the example.

I'm struggeling with this to.
I have tried you sample code.
Error --> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 66.249.93.111:587

Tried port 465.
Error --> System.Net.Mail.SmtpException: The operation has timed out.

I'm fighting with this sor about a week now.
Nothing works.

Using an spplication like outlook express or so works fine.
So I am able to do this from my computer/location. Just not with my own VB-program.

Friendly greetings
Rens (Frustrated)
 
No connection could be made because the target machine actively refused it 66.249.93.111:587

Looks like false credentials, make sure the info is right, i.e. correct username, password

System.Net.Mail.SmtpException: The operation has timed out.

Wrong port - the first error is Good, in the sense that it actually tried to verify you.
 
Hm.....
Might be, but hear this:
Using PuTTY.exe --> Tried to open an HSS connection to 465 --> Operation timed out.
But way is on the google settings page port 465 mentioned one should use?
And why does it work fine with for instance Outlook Express?
Look at page: http://mail.google.com/support/bin/answer.py?answer=13276&topic=12810
Okay... It's dutch, but find the sentence: "Je client handmatig configureren:"
See point 14......



Now I try, using PuTTY.exe to connect on port 587.
Right after clicking 'Open', I get the message: Unable to open connection to smtp.google.com Network error: Connection refused
I do not even get the change to enter a username and password.
Shouldn't this work?

Further:
Tried in my VB program.
Username and password are absolutely correct, because all works fine in Outlook Express and/or Live Mail and so on.


Clueless.......

Rens
 
Unable to open connection to smtp.google.com Network error: Connection refused

I suggest that you make sure your VB program is connecting with SSL. You may need to tweak with the credential, but make sure at all costs this line is there:

theSender.EnableSsl = True

If your trying to connect to Google Mail and your getting refused, its either bad port, username, password or SSL, or a combination. It's case sensitive and the username has to have @gmail.com at the end I think.

EDIT: Oh yeah, and I wouldn't rely on Putty for anything more than pinging XD
 
Back
Top