# Emails in C++

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I been doing some searching and I have not fount any thing that can give me a sample of how to send a email in C++. Thanks again Joe

##### Share on other sites
That's probably because C++ has no concept of "email". However, you can write code to do this, but it will require knowledge of network programming. You will need to open a socket to an email server (usually port 25), and then communicate with it using the Simple Mail Transfer Protocol (SMTP).

##### Share on other sites
You're probably referring to the email function that is available in PHP. The PHP function will either call a local MTA to send the email, or will act as a MTA itself.

Regardless, you should regard C++ not to have an MTA available, as the majority of OSes don't (Windows being a prime example). SMTP protocol is not complex, in fact, it's human readable. If you wanted to, you could telnet emails.

##### Share on other sites
Sorry, I guess that too complexed for me. I was hoping there would be an easy way of doing it in c++

Thanks

##### Share on other sites
You are using the wrong language if you want to be able to easily program tasks like sending e-mails and the like.

##### Share on other sites
Not realy, I just wanted to know if there was an easy way of doing it, So I could add that option to some of my projects.

##### Share on other sites
Quote:
 Original post by bigjoe11aNot realy, I just wanted to know if there was an easy way of doing it, So I could add that option to some of my projects.

Really, it isn't much more difficult than to program than downloading a file from the web. There are also a couple of C++ SMTP libraries on the web that simplify it to the level of php.

##### Share on other sites
Well Thats fine. I just don't know how to use them

##### Share on other sites
If you download install and experiment with them, eventually you will understand through usage. There are no magic books or articles which can explain. It will take some doing but you will learn what you need through doing it.

##### Share on other sites
Quote:
 Original post by speciesUnknownIf you download install and experiment with them, eventually you will understand through usage. There are no magic books or articles which can explain. It will take some doing but you will learn what you need through doing it.

Thanks. Downloading them is the easy part. Just finding out what to download. and How to set it up. That would take some doing. I have to try and find some help on this.

Thanks

##### Share on other sites
sendemail

Then use
#include <stringstream>#include <string>...std::ostringstream buf;buf << "sendmail.exe ";        // path to sendmail.exebuf << "-f " << address_from;  // sender's addressbuf << "-m " << message_body;  // bodybuf << "-s " << smtp_host;     // server to use for sendingbuf << // any other parameters you want to sendsystem(buf.str().c_str());

It's somewhat ugly, but should get the job done with minimum fuss.

##### Share on other sites
doesnt libcurl support smtp?

##### Share on other sites
Quote:
 Original post by AntheussendemailThen use *** Source Snippet Removed ***It's somewhat ugly, but should get the job done with minimum fuss.

Thanks, But I thought there was an option to send emails with smtp in C++. I guess C++ is limited.

##### Share on other sites
Quote:
Original post by bigjoe11a
Quote:
 Original post by AntheussendemailThen use *** Source Snippet Removed ***It's somewhat ugly, but should get the job done with minimum fuss.

Thanks, But I thought there was an option to send emails with smtp in C++. I guess C++ is limited.

Because it depends on external libraries for almost everything. If you are unwilling to learn how to use libraries then you will never be able to do something non trivial in C++. There are languages out there that have large standard libraries, like Ruby.

Libraries aren't especially difficult. It won't take you long to get the hang of using them if you apply yourself.

##### Share on other sites
Quote:
Original post by bigjoe11a
Quote:
 Original post by AntheussendemailThen use *** Source Snippet Removed ***It's somewhat ugly, but should get the job done with minimum fuss.

Thanks, But I thought there was an option to send emails with smtp in C++. I guess C++ is limited.

Actually C++ is one of the most unlimited languages. Ok so it may not have email sending functions built in, but if you took that attitude then noone would use it for anything since functionality comes from libraries (which are often written in C++). If you wanted to do this manually i suggest looking up the RFC for SMTP (as mentioned already) which will show you the packet structure that you need to send to mail servers.

##### Share on other sites
Quote:
Original post by Dave
Quote:
Original post by bigjoe11a
Quote:
 Original post by AntheussendemailThen use *** Source Snippet Removed ***It's somewhat ugly, but should get the job done with minimum fuss.

Thanks, But I thought there was an option to send emails with smtp in C++. I guess C++ is limited.

Actually C++ is one of the most unlimited languages. Ok so it may not have email sending functions built in, but if you took that attitude then noone would use it for anything since functionality comes from libraries (which are often written in C++). If you wanted to do this manually i suggest looking up the RFC for SMTP (as mentioned already) which will show you the packet structure that you need to send to mail servers.

Dave I think you need to change your attitude. Remember that finding help at all is not all ways available for most Libraries. If you want to help. Then your well come to give me a clue. Or Please don't post. Your wasting my time and every one else's time.

My point is that if you want to take the time to help me setup and install the libraries. Thats fine. Or just don't post at all

##### Share on other sites
Actually, you're the one wasting peoples time by refusing to apply yourself and asking for help for every little thing. If you aren't willing to do some work on your own then why should people want to help you?

##### Share on other sites
Quote:
 Original post by AntheussendemailThen use *** Source Snippet Removed ***It's somewhat ugly, but should get the job done with minimum fuss.

Note: <sstream>, not <stringstream>. Sad but true.

##### Share on other sites
Quote:
 Remember that finding help at all is not all ways available for most Libraries.

What have you tried? What libraries did you download? Where did you get stuck? What did not work? I have used a number of C++ libraries in my day and have yet to find one that did not come with some form of documentation. It may not have a full on hold-your-hand-start-to-finish tutorial, but it will at least have a README file that explains any set up instructions, and then comments in the source code to help you figure out how to use it.
C++ is a pretty low level language. You can do anything you want to with it, including create email sending functionality. The problem is, you have to write the code yourself. There is no built-in SendEmail() function. You can build such a function by writing the underlying network code and then using SMTP. But unless you are just trying to learn how email systems work, you should use a language that has email capability. Maybe if you explain what you are trying to do, someone can suggest a language more suitable for your project.

Looking at your other post, if you want SQL and email capability, why don't you use PHP? Why do you insist on using C++? If you want help, why don't you start helping us by explaining the problem *completely*. That means outline the steps that *you* have already tried, and where you are getting stuck. Let us understand what you are doing and why it has to be done in C++. It seems like you keep posting the same kinds of questions and getting the same answers. I only tell you this because it is the kind of pattern that will eventually get you completely ignored. If that is not your goal, then help us help you.

[Edited by - CodeMunkie on February 12, 2008 2:18:56 PM]

##### Share on other sites
Quote:
Original post by CodeMunkie
Quote:
 Remember that finding help at all is not all ways available for most Libraries.

What have you tried? What libraries did you download? Where did you get stuck? What did not work? I have used a number of C++ libraries in my day and have yet to find one that did not come with some form of documentation. It may not have a full on hold-your-hand-start-to-finish tutorial, but it will at least have a README file that explains any set up instructions, and then comments in the source code to help you figure out how to use it.
C++ is a pretty low level language. You can do anything you want to with it, including create email sending functionality. The problem is, you have to write the code yourself. There is no built-in SendEmail() function. You can build such a function by writing the underlying network code and then using SMTP. But unless you are just trying to learn how email systems work, you should use a language that has email capability. Maybe if you explain what you are trying to do, someone can suggest a language more suitable for your project.

Looking at your other post, if you want SQL and email capability, why don't you use PHP? Why do you insist on using C++? If you want help, why don't you start helping us by explaining the problem *completely*. That means outline the steps that *you* have already tried, and where you are getting stuck. Let us understand what you are doing and why it has to be done in C++. It seems like you keep posting the same kinds of questions and getting the same answers. I only tell you this because it is the kind of pattern that will eventually get you completely ignored. If that is not your goal, then help us help you.

Well one of the libraries was called pcuc??? some thing. It was an library was would help me to make Boxes, Lines and things like that in C++. and the other libraries I check out cost TOO MUCH. I couldn't find any thing for less then $300. and as for the free ones. I can't get support for them. Its like if you follow the doc's to install it and then you try a sample that they have and then it doesn't work. Well its like no one cares if it working or not. #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by bigjoe11aWell one of the libraries was called pcuc??? some thing. It was an library was would help me to make Boxes, Lines and things like that in C++. and the other libraries I check out cost TOO MUCH. I couldn't find any thing for less then$300. and as for the free ones. I can't get support for them.

Support is where the money is, code is free. That's just how it works. Even for open source software - people pay developers for support, not the code.

Why didn't you want to try the sendemail solution I've shown? It avoids third-party libraries, it's free, and requires no extra steps to get working. All it requires you is to set up the parameters and call it. It gets the job done, but avoid all the other issues you're having.

It's just as much C++ as anything else. In order to send email you need Winsock. That one is an external application as well, provided as DLL by Windows, sendemail comes as exe. That's the only difference.

Quote:
 Note: , not . Sad but true.

Yea,... flu, fever and all that...

##### Share on other sites
Quote:
Original post by Antheus
Quote:
 Original post by bigjoe11aWell one of the libraries was called pcuc??? some thing. It was an library was would help me to make Boxes, Lines and things like that in C++. and the other libraries I check out cost TOO MUCH. I couldn't find any thing for less then \$300. and as for the free ones. I can't get support for them.

Support is where the money is, code is free. That's just how it works. Even for open source software - people pay developers for support, not the code.

Why didn't you want to try the sendemail solution I've shown? It avoids third-party libraries, it's free, and requires no extra steps to get working. All it requires you is to set up the parameters and call it. It gets the job done, but avoid all the other issues you're having.

It's just as much C++ as anything else. In order to send email you need Winsock. That one is an external application as well, provided as DLL by Windows, sendemail comes as exe. That's the only difference.

Quote:
 Note: , not . Sad but true.

Yea,... flu, fever and all that...

Because I didn't want to add 3rd party software to my software. Thats all it is for me is just some thing to learn.

##### Share on other sites
You really could have googled for the information yourself by now based on what people have told you, but anyways...

Johnnys Winsock Tutorial
SMTP RFC

Work through the first link to learn how to open, read & write, close and do other cool shit with sockets in windows. Then have a look through the RFC. Somewhere in there is probably a diagram showing you how to structure the packets that you need to send and you will recieve.

If you don't want to involve 3rd party code then this is what you need to do, there is no way around it.

##### Share on other sites
Quote:
 Original post by DaveYou really could have googled for the information yourself by now based on what people have told you, but anyways...Johnnys Winsock TutorialSMTP RFCWork through the first link to learn how to open, read & write, close and do other cool shit with sockets in windows. Then have a look through the RFC. Somewhere in there is probably a diagram showing you how to structure the packets that you need to send and you will recieve.If you don't want to involve 3rd party code then this is what you need to do, there is no way around it.

Dave thanks. I was hoping for an easy way. Every one is saying to use a library. So until I can find a free library some where that will let me send emails and use a SQL 2005 database. I don't know that much a bout C++ to start working with sockets at this time. My tutor doesn't think I ready for that yet.

##### Share on other sites
Quote:
Original post by bigjoe11a
Quote:
 Original post by DaveYou really could have googled for the information yourself by now based on what people have told you, but anyways...Johnnys Winsock TutorialSMTP RFCWork through the first link to learn how to open, read & write, close and do other cool shit with sockets in windows. Then have a look through the RFC. Somewhere in there is probably a diagram showing you how to structure the packets that you need to send and you will recieve.If you don't want to involve 3rd party code then this is what you need to do, there is no way around it.

Dave thanks. I was hoping for an easy way. Every one is saying to use a library. So until I can find a free library some where that will let me send emails and use a SQL 2005 database. I don't know that much a bout C++ to start working with sockets at this time. My tutor doesn't think I ready for that yet.

Ok, that is fine.

Maybe this is what you're looking for.

##### Share on other sites

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

• ### Forum Statistics

• Total Topics
628676
• Total Posts
2984179

• 13
• 12
• 9
• 10
• 10