Sending emails to MS Exchange server

Get help on programming - C++, Java, Delphi, etc.
Post Reply
PypLaCe
Registered User
Posts: 214
Joined: 19 Apr 2005, 02:00
Location: Johannesburg
Contact:

Sending emails to MS Exchange server

Post by PypLaCe »

Sup! I wrote a class in VB.NET 2.0 which I use to send emails.
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
This is quite urgent so any help would be much appreciated!
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

Well There is a bigg diff between Exchange and SMTP.


I dont think it s comparble (Not because of the big differance) but because its not the same thing.

Exchange is for sending and receiving on a completely different port to
an Exchange connected client. and is not only for mail it shares Calenders amongs people , public folders, and quite a few things more.

In the end An exchange needs SMTP to send mail and receive mail.

So in theory your code should work.

Client - SMTP ---> Exchange -- Exchange Client

or Exchange Client ----- Exchange ---> SMTP ----> SMTP Client.

Test by doing this in the office where exchange is.

Lets say the Exchange IP is 10.0.0.10

click start then run and type CMD
the the promt type the following

Code: Select all

telnet 10.0.0.10 25
HELLO
MAIL FROM: FakeEmail@Hello.com
RCPT TO: RealEmailOnExchange@Yourcompany.com
DATA
Type any message here
.
quit
It will then send a mail from
FakeEmail@Hello.com

The above is just been tested on an exchange server.
Bare in mind that the SMTP server in the office where exhcange is might only accept mails from a spam machine on a different IP address.

So you might have to send to the spam machine first.
also the firewall might block SMTP on the internal network and only allow
mail from the external network (The domain)
neon_chameleon
Moderator Emeritus
Posts: 6098
Joined: 27 Feb 2004, 02:00
Location: Durban
Contact:

Post by neon_chameleon »

What opensource mail exchange servers can be used? I have found a few but can't get any to work on a windows box. Any ideas, SBSP?
Qualifications: BSc Computer Science & Information Technology, BCom Information Systems Honours, ISACA CISA, ISACA CRISC
Experience: Web Design, IT Auditing, IT Governance, Computer Retail, IT Consulting
Interests: Technology, Nutrition, Toasters, BBM, Facebook, Colourful Diagrams
User avatar
hamin_aus
Forum Moderator
Posts: 18363
Joined: 28 Aug 2003, 02:00
Processor: Intel i7 3770K
Motherboard: GA-Z77X-UP4 TH
Graphics card: Galax GTX1080
Memory: 32GB G.Skill Ripjaws
Location: Where beer does flow and men chunder
Contact:

Post by hamin_aus »

SBSP wrote:Well There is a bigg diff between Exchange and SMTP.
What he said.

The command
Dim smtp As New SmtpClient(mSMTP)
smtp.UseDefaultCredentials = True


Wont work for exchange because it are no POP/SMTP credentials.
So naturlally everything after that is not going to work either.

I remember from VB6/Exchange 5.5 (many years ago) that you can install and use CDO to send mails via exchange. Maybe it would be worth a google, as I dont know if this still works.

This is what I found quickly....

http://support.microsoft.com/kb/161833

Good luck to you!
Image
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

neon_chameleon wrote:What opensource mail exchange servers can be used? I have found a few but can't get any to work on a windows box. Any ideas, SBSP?

Well I have never found any a while back i wanted an open source Exchange
but couldn't find anything.

I assume you wont get an open source exchange that is compatible to Outlook.
Because of the microsoft's patents. (Thats just my view)

But You say you have found some for linux ?
What's the package name ?
and is it compatible to Outlook's connect to exchange function?
Post Reply