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?

If I try port 25, I get this message-

System.Web.HttpException: The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040211): The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

--- 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

SmtpMail.SmtpServer = "mysmtpserver"

mysmtpserver, did you stated this value for testingpurposes? It should be a real smtpserver like mail.yourcompany.com.....

Regards,
Richard
The Netherlands

[edit]
Be aware that most smtp servers don't respond on RELAY. Systemadministrators block relaying their smtp server ;)

I did put valid values in the actual code I used, just did not want to post it here.

Have used a correct smtp server, username, password - sure of that

It should work with the fields.add() like you mentioned before. Did you also checked if your firewall blocks ports 25? If so, port 2525 might do the job....

No luck with port 2525 either, have disabled my firewall too.

Any other troubleshooting steps?

Thanks a lot for your ideas.

This article has been dead for over six months. Start a new discussion instead.