cgipro2007
11-25-2007, 12:14 PM
I have a windows 2003 server that has a mail server running on it. I already tested this mail server if it's working or not. The way I tested it was through creating an email address on that server and then I added that email account to be one of my available email accounts in Microsoft Outlook.
Of couse you know that MS Outlook asks for the incoming POP3 and outgoing SMTP servers. So, I provided them to it when I was adding that email. I then tested the email for retrieval and sending and it worked just fine. So, I concluded the fact that my POP3 and SMTP servers were the correct ones.
So I created the following VB.NET function:
Function SendMail(ByVal SMTPServer As String, ByVal SenderEmail As String, ByVal SendTo As String, ByVal MsgSubject As String, ByVal MsgBody As String) As String
Dim MyMail As System.Web.Mail.SmtpMail
Dim MailMsg As New System.Web.Mail.MailMessage
MyMail.SmtpServer = SMTPServer
MailMsg.From = SenderEmail
MailMsg.To = SendTo
MailMsg.BodyFormat = MailFormat.Html
MailMsg.Subject = MsgSubject
MailMsg.Body = MsgBody
Try
MyMail.Send(MailMsg)
Return ""
Catch ex As Exception
Return ex.Message
End Try
End Function
As you can see, one of those function arguments is the SMTP server address.
Whenever I want to send email, I use this function and I pass to it the same SMTP server address I already tested in Outlook previously. However, the function throws the exception [The transport failed to connect to the server.].
Why is that?
Note: My Outgoing server requires authentication. So if this is the problem, then my function up there needs to set this authentication, but I don't know how!! And if this function doesn't work with outgoing servers needing authentication then is there another way of sending email with VB.NET?
Of couse you know that MS Outlook asks for the incoming POP3 and outgoing SMTP servers. So, I provided them to it when I was adding that email. I then tested the email for retrieval and sending and it worked just fine. So, I concluded the fact that my POP3 and SMTP servers were the correct ones.
So I created the following VB.NET function:
Function SendMail(ByVal SMTPServer As String, ByVal SenderEmail As String, ByVal SendTo As String, ByVal MsgSubject As String, ByVal MsgBody As String) As String
Dim MyMail As System.Web.Mail.SmtpMail
Dim MailMsg As New System.Web.Mail.MailMessage
MyMail.SmtpServer = SMTPServer
MailMsg.From = SenderEmail
MailMsg.To = SendTo
MailMsg.BodyFormat = MailFormat.Html
MailMsg.Subject = MsgSubject
MailMsg.Body = MsgBody
Try
MyMail.Send(MailMsg)
Return ""
Catch ex As Exception
Return ex.Message
End Try
End Function
As you can see, one of those function arguments is the SMTP server address.
Whenever I want to send email, I use this function and I pass to it the same SMTP server address I already tested in Outlook previously. However, the function throws the exception [The transport failed to connect to the server.].
Why is that?
Note: My Outgoing server requires authentication. So if this is the problem, then my function up there needs to set this authentication, but I don't know how!! And if this function doesn't work with outgoing servers needing authentication then is there another way of sending email with VB.NET?