I have not found any answer on Daniweb neither on the web.

What I need is a winform that send an e-mail using the Exchange Server on the local network are and authenticate with the current domain user without entering credentials.

It is possible?

I have this code? Can anyone confirm if im making this the correct way?

Dim server As String = ""
        Dim port As Integer = ""

        Dim from As String = ""
        Dim [to] As String = ""

        Dim subject As String = "Message subject"
        Dim body As String = "Body message"
        Dim message As New MailMessage(from, [to], subject, body)
        Dim client As New SmtpClient(server, port)

        client.Credentials = CredentialCache.DefaultNetworkCredentials

        Try
            client.Send(message)

        Catch ex As Exception

            MsgBox(ex)

        End Try

A couple of things. First port is an integer it should be initialized to 0 not "". Second both server and port must have actual valuesfor it to work right.

host
Type: System.String
A String that contains the name or IP address of the host used for SMTP transactions.

port
Type: System.Int32
An Int32 greater than zero that contains the port to be used on host.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.