Hi!
This is the code I have for sending mail-
Imports System.Web.Mail
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Mailmsg As New System.Web.Mail.MailMessage()
SmtpMail.SmtpServer = "mysmtpserver"
Mailmsg.To = "recepient@domain.com"
Mailmsg.From = "\" & "foo" & "\ <" & "bar@domain.com" & ">"
Mailmsg.Subject = "Sending a test mail"
'Mail Body
Mailmsg.Body = "This is a test message"
Mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
Mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "myusername") 'set your username here
Mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mypassword") 'set your password here
Mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "26") 'Put port number here
Try
SmtpMail.Send(Mailmsg)
Catch ex As Exception
'MsgBox(ex.ToString)
Me.TextBox1.Text = ex.ToString
End Try
End Sub
End Class
The error message I get is-
System.Web.HttpException: The transport failed to connect to the server.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server.
--- End of inner exception stack trace ---
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
--- End of inner exception stack trace ---
at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)
at MyMailer.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\tuse\AppData\Local\Temporary Projects\MyMailer\Form1.vb:line 32
---------
Tried to google, but no luck.
Any ideas?