Suhail Gupta
Suhail Gupta

Reputation: 23256

sending e-mail from c++ code

I am making a console app that needs to send e-mail when asked so.How could i do that ? Though i tried this link it was not successful, because you need additional software for it. AND there is a delay of about 10 minutes when i actually get the email.what could be the problem ?

This is the dialog box displayed when you run the first code

enter image description here

Is there any other way out ?

Are there any links that explain sending e-mail from c++ program step by step explaining the function used in the code.

Upvotes: 1

Views: 5183

Answers (5)

René Richter
René Richter

Reputation: 3909

For sending eMail you can open a tcp network socket to the mailserver of the recipient, e.g. smtpmail.example.com, port 25.

For details to Windows sockets programming see http://www.snible.org/winsock/ or other tutorials.

Then write text to that socket according to the SMTP protocol:

HELO mymachine_ipaddress_or_dnsname
MAIL FROM:<[email protected]>
DATA

From: <[email protected]>
To: <[email protected]>
Subject: Test message

Hello, greetings.
.
QUIT

Then close socket. In fact, there is no built-in sender authentication in SMTP...

Upvotes: 2

Naszta
Naszta

Reputation: 7744

If you just want to open a mail window in your default mail agent, use ShellExecute:

ShellExecute(
  NULL,
  NULL,
  TEXT("mailto:[email protected]"),
  NULL,
  NULL,
  SW_SHOWNORMAL);

Additionally: connected topic: C++ SMTP Example.

Upvotes: 3

ferosekhanj
ferosekhanj

Reputation: 1074

you can use CDO for doing this. I think it bypases the outlook object model. So you wont get this warning dialogue also.

Upvotes: 0

Vijay Mathew
Vijay Mathew

Reputation: 27174

libCurl is a highly portable C/C++ networking library that supports SMTP. There is a sample on their site.

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 477060

Give VMime a try!

(Sending mail is not a language built-in feature, you will have to use some sort of library.)

Upvotes: 4

Related Questions