VB.net Suggestions for SMTP client connection error, trying to send message through exchange server

StackOverflow https://stackoverflow.com/questions/22156333

سؤال

So I'm trying to connect to our exchange server and send a message through vb.net using the smtpClient. Here is my code:

    Dim smtp As New SmtpClient("exchangeserver.com")
    Dim mail As New MailMessage
    mail.From = New MailAddress("me@me.com")
    mail.To.Add("me@me.com")
    mail.Subject = "Test Email"
    mail.Body = "Testing body."
    Try
        smtp.Send(mail)
    Catch exc As Exception
        Console.WriteLine(exc.ToString)
    End Try

The exception I'm getting indicates that:

 System.Net.Mail.SmtpException: Failure Sending mail. --->
 System.Net.WebException: Unable to connect to the remote server --->
 System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions ##.##.#.##:25

Seems like I can't connect on that port? No permissions... should I try something else or revert back to sending emails through outlook?

لا يوجد حل صحيح

نصائح أخرى

one thing to check... you may need to set credentials... look into this

smtp.Credentials = New Net.NetworkCredential( "blah blah blah", "yada yada")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top