Link to home
Start Free TrialLog in
Avatar of daniblum
daniblum

asked on

Send email through Exchange Server programmatically (C++, SDK, no MFC, no .NET)

Hello,

I need to send email messages using an Exchange Server. I am programming in C/C++ (MSVC .NET 2003) and I am not using (nor do I intend to use) MFC or ASP.
How should I proceed?
Is there an SDK for that purpose anywhere? I've been looking around, no results yet.

Thank you,

Daniel
Avatar of ashutosh_kumar
ashutosh_kumar
Flag of India image

.net already has SmtpMail class...but use it only for framework 1.1. For higher version of framework use SmtpClient class

see the code below
#using <mscorlib.dll>
#using <System.dll>
#using <System.Web.dll>
using namespace System;
using namespace System::Web::Mail;
 
void DisplayUsage() 
{
   Console::WriteLine(S"Usage SendMail.exe <to> <from> <subject> <body>");
   Console::WriteLine(S"<to> the addresses of the email recipients");
   Console::WriteLine(S"<from> your email address");
   Console::WriteLine(S"<subject> subject of your email");
   Console::WriteLine(S"<body> the text of the email");
   Console::WriteLine(S"Example:");
   Console::WriteLine(S"SendMail.exe SomeOne@Contoso.com;SomeOther@Contoso.com Me@contoso.com Hi hello");
}
 
int main() 
{
   String* args[] = Environment::GetCommandLineArgs();
   try 
   {
      try 
      {
         MailMessage* Message = new MailMessage();
         Message->To = args[1];
         Message->From = args[2];
         Message->Subject = args[3];
         Message->Body = args[4];
 
         try 
         {
            SmtpMail::SmtpServer = S"your mail server name goes here";
            SmtpMail::Send(Message);
         } 
         catch (System::Web::HttpException* ehttp) 
         {
            Console::WriteLine(S" {0}", ehttp->Message);
            Console::WriteLine(S"Here is the full error message output");
            Console::Write(S" {0}", ehttp);
         }
      } 
      catch (IndexOutOfRangeException*) 
      {
         DisplayUsage();
      }
   } 
   catch (System::Exception* e) 
   {
      Console::WriteLine(S"Unknown Exception occurred {0}", e->Message);
      Console::WriteLine(S"Here is the Full Message output");
      Console::WriteLine(S" {0}", e);
   }
}

Open in new window

if you intend to use higher version of .net , see my post (its second post) on

https://www.experts-exchange.com/questions/23113345/The-transport-failed-to-connect-to-the-server.html
Avatar of daniblum
daniblum

ASKER

Like I said, I am not planning to use .NET. I need this application to be as self-contained as possible.
Still looking...
ASKER CERTIFIED SOLUTION
Avatar of ashutosh_kumar
ashutosh_kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you. Actually, I could do it using SMTP only, and I needed this as an alternative when the users only have Exchange Server and no SMTP server.