corteplaneta
Member
- Joined
- Nov 14, 2008
- Messages
- 10
- Programming Experience
- 3-5
Hello,
I've been attempting to write an application that sends mail through the company exchange server. This exchange server does not have basic authentication enabled, only TLS.
I've quickly borrowed some code from somewhere on the net (sorry, I would cite if I remembered where I got it) to test out connecting to our exchange server & sending mail via SMTP.
Here's the code...
When attempting to run this code, I'm given an error stating "System.Security.AUthentication.AuthenticationException: The remote certificate is invalid according to the validation procedure at..." blah blah blah.
If I disable SSL for the SMTP server, I receive error "System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay...blah blah blah"
Now to go a bit off topic.......
Being I couldn't seem to connect using either method, I decided to attempt to telnet into the exchange server. With just TLS enabled, I run the "AUTH LOGIN" command and simply receive and error stating that this is an unrecognized authentication type.
Reading a little more into this, I enabled "Basic Authentication" for the receive connector, and this time actually got the "AUTH LOGIN" command to execute--but this time, using both my username & username@domain.com were rejected and the message "Authentication unsuccessful" was returned.
If anyone has any knowledge in exchange 2007 or any ideas of what to do from here, they would be GREATLY appreciated.
Thanks,
corteplaneta.
I've been attempting to write an application that sends mail through the company exchange server. This exchange server does not have basic authentication enabled, only TLS.
I've quickly borrowed some code from somewhere on the net (sorry, I would cite if I remembered where I got it) to test out connecting to our exchange server & sending mail via SMTP.
Here's the code...
VB.NET:
Imports System.Net.Mail
Namespace TNE.DocGen
Public Class Mailer
Public Shared Sub SendEmail(ByVal sender As String, _
ByVal recipient As String, ByVal subject As String, _
ByVal body As String, Optional ByVal attachmentString As String = "")
Dim fromAddress As New MailAddress(sender)
Dim toAddress As New MailAddress(recipient)
Dim message As New MailMessage(fromAddress, toAddress)
Dim mailSender As SmtpClient = New SmtpClient("exchsvr", 25)
With mailSender
.Credentials = New Net.NetworkCredential("testuser", "!testuserpw!")
.UseDefaultCredentials = False
.EnableSsl = True
End With
message.Bcc.Add(fromAddress)
message.Subject = subject
message.IsBodyHtml = False
message.Body = body
If Not attachmentString = "" Then
Dim msgAttach As New Attachment(attachmentString)
message.Attachments.Add(msgAttach)
End If
Try
mailSender.Send(message)
MsgBox("Message successfully sent.", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical)
Throw New Exception(ex.ToString)
End Try
End Sub
End Class
End Namespace
When attempting to run this code, I'm given an error stating "System.Security.AUthentication.AuthenticationException: The remote certificate is invalid according to the validation procedure at..." blah blah blah.
If I disable SSL for the SMTP server, I receive error "System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay...blah blah blah"
Now to go a bit off topic.......
Being I couldn't seem to connect using either method, I decided to attempt to telnet into the exchange server. With just TLS enabled, I run the "AUTH LOGIN" command and simply receive and error stating that this is an unrecognized authentication type.
Reading a little more into this, I enabled "Basic Authentication" for the receive connector, and this time actually got the "AUTH LOGIN" command to execute--but this time, using both my username & username@domain.com were rejected and the message "Authentication unsuccessful" was returned.
If anyone has any knowledge in exchange 2007 or any ideas of what to do from here, they would be GREATLY appreciated.
Thanks,
corteplaneta.