How can I send an email through C++. I need to make the following:

bool SendMail(char* from, char* to, char* title, char* msg)
{
    //What now?
    //Return true on success, false otherwise
}

>> How can I send an email through C++.


You don't. Or at least you don't through standard C++. You need to either use something like libcurl and pass this information to some language like PHP which DOES have built-in mail functionality or you need to find some other C++ library that can mail things without using something like PHP as an intermediary. I've done the former many times. Never done the latter.

http://curl.haxx.se/libcurl/cplusplus/

But you're not going to find anything within Standard C++ that does what you are trying to do.

I don't fully understand. Is there some way to find some kind of tutorial for libcURL?

Allow me :icon_rolleyes:

Maybe you can learn something from this post...

commented: Awesome :D +6

That was an awesome link! You are right, google is our friend. Thanks a lot!

I could have sworn I gave you that exact same link. How come Walt gets rep and I don't? :icon_cry:

Yes, "Let me google that for you" is a cool site.

commented: Lol, Life's Unfair :) .. +9

I have a problem. I have tried absolutely everything from libcurl to telnet commands. For some unknown reason they all end up giving me some kind of warning or another saying that the message simply could not be sent. I was thinking maybe since I use an unusual Email provider I am unable to send emails or something. But I have the smtp so it shouldn't be too big a problem. Any ideas of why I cannot send my emails?

I have a problem. I have tried absolutely everything from libcurl to telnet commands. For some unknown reason they all end up giving me some kind of warning or another saying that the message simply could not be sent. I was thinking maybe since I use an unusual Email provider I am unable to send emails or something. But I have the smtp so it shouldn't be too big a problem. Any ideas of why I cannot send my emails?

Details, details. There are several possible problems/explanations/solutions. The explanation/solution will depend on the problem. We don't know what you've tried. As mentioned, I've only done it through some server-side script like PHP or Perl, so if you're doing it another way, I'm of no help. Several scenarios, assuming you're passing from a C++ executable on some personal computer using CURL to a properly configured server-side script like PHP which does the mail.

  1. Info never gets from the C++ program to the PHP script.
  2. PHP script doesn't mail it correctly.
  3. PHP script mails it fine, but the mail server on either end rejects it or whatever and the mail never gets it.
  4. PHP script mails it fine, the actual e-mail gets sent, but somehow, PHP doesn't return the correct message to the C++ program via libcurl.
  5. PHP sends it back fine, but it never gets back to the C++ program due to firewall, etc.
  6. C++ Libcurl/gets it back fine, but there's some bug in the C++ program.

1, and 6 I can help with provided it's not some firewall or port issue or something. 2 and 4 I can help with, but there's a PHP forum so it might be better to ask about PHP's mail function there. Ditto Perl or any other language.

Routers, firewalls, e-mail server configuration, etc., you have the wrong guy and definitely the wrong forum. If you're doing it any other way than posting from a C++ program to a server-side mailing script, I can be of no help. Make sure it's a problem with the C++/Curl end of it by doing a mail directly from the server(i.e. no C++ program). If so, report back with the precise error and the code.

*FACEPALM*
Drat! Foisted by my own spam filter. -Sheldon Cooper
As it turns out all the random methods I tried worked. They just ended up in my spam filter. Thank you for the help anyways!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.