I have a legacy VB6 codebase which I would like to extend to include support for sending mails through an external SMTP server (smtp.live.com).
I use CDO for sending the mail. My machine runs Windows 7. Unfortunately I get a "The transport failed to connect to the server" error message when trying to send send the mail. Below is the code.
VB6
Dim oNewMessage As CDO.Message
Dim iConf As New CDO.Configuration
Dim oFlds As ADODB.Fields
Dim strbody As String
On Error GoTo errSMPT
iConf.Load cdoDefaults
Set oFlds = iConf.Fields
oFlds(cdoSendUsingMethod) = cdoSendUsingPort
oFlds(cdoSMTPServer) = "smtp.live.com"
oFlds(cdoSMTPServerPort) = 587
oFlds(cdoSMTPConnectionTimeout) = 30
oFlds(cdoSMTPUseSSL) = True
oFlds(cdoSMTPAuthenticate) = cdoBasic
oFlds(cdoSendUserName) = "[email protected]"
oFlds(cdoSendPassword) = "mypassword"
oFlds.Update
strbody = "Sample message " & Time
Set oNewMessage = New CDO.Message
Set oNewMessage.Configuration = iConf
With oNewMessage
.To = txtTo.Text
.From = txtFrom.Text
.Subject = "subject"
.TextBody = strbody
.Send
End With
Exit Sub
errSMPT:
MsgBox Err.Description
I don't think that the problem is related to firewall or account security issues since the C# code below works without any problems.
C#
using (MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtText.Text))
{
SmtpClient mailClient = new SmtpClient("smtp.live.com", 587);
mailClient.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
mailClient.EnableSsl = true;
mailClient.Send(message);
MessageBox.Show("Message successfully sent!!!");
}
Any help is appreciated!
Thanks
//Peter