Now, in the one office where they use my program, they have an smtp server and there the code works perfectly, but in the other office, they use a MS Exchange server, and there the code does not work at all. I'm no expert in mail servers so I would just like to know what the difference is between these servers and what must I do differently in my code to make it work at both offices (or rather at the office where they have the exchange server) ?
Here is the code I have at the moment:
Code: Select all
'Variables that is used to send the email.
Private mFromAddress As String
Private mToAddress As String
Private mSubject As String
Private mBody As String
Private mSMTP As String
Private mFile As String
'Instantiation of the variables used to send the emial.
Public Sub New(ByVal fromAddress as String, ByVal toAddress as String, ByVal subject as String, ByVal body as String, ByVal smtp as String)
mFromAddress = fromAddress
mToAddress = toAddress
mSubject = subject
mBody = body
mSMTP = smtp
End Sub
Public Function sendEmail() As Boolean
Try
'Create the message object.
Dim message As New MailMessage(mFromAddress, mToAddress, mSubject, mBody)
'Get smtp settings
Dim smtp As New SmtpClient(mSMTP)
smtp.UseDefaultCredentials = True
'Send email
smtp.Send(message)
Return True 'Returns true if message was sucessfully sent.
Catch ex As Exception
Return False 'Returns false if message was not sucessfully sent.
End Try
End Function