How do I send an email (files) to mail recipient
from my C/C++ program code :
I need to send existing files .
What is the code for it ?
I use windows XP VisualStudio C++
How do I do it in C# ?
How do I send an email (files) to mail recipient
from my C/C++ program code :
I need to send existing files .
What is the code for it ?
I use windows XP VisualStudio C++
How do I do it in C# ?
At minimum, you need a TCP/IP client. You might need a TCP/IP server. You could then learn enough of the SMTP protocol to do what you want, it is probably not that complicated. There may some libraries around to cover that, altho a quick google didn't turn up too much WRT C/C++.
I would not rely on sending general mail directly from an individual computer; many large ISPs will just chuck whatever you send them without looking at it. The extent and consequences of that are debatable:
http://cboard.cprogramming.com/proje...ml#post1081568
So consider yourself warned, but don't take my word for it if you don't want to.
There may also be some open source mail server that you can plug into, I dunno, but the same whitelist problem still applies. Your best bet is probably to use your real email address and send to your ISP's mailserver, the same way your regular email software does.
Last edited by MK27; 01-24-2012 at 01:41 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Thanks
I don't need a mail server or client.
I only want to send one file from my application,
when the user clicks on a button.
and only for Windows.
I think that in C# (windows), they have a class
and It requires only to call it like :
files: MyFilesObject
and then MyFilesObject.sendFile (... filename .. )
So How would I do it in C++ ?
As the guy above said - you either need to write it or find a library of someone that's already written it. It's *NOT* as simple as just a one-liner in C++. For a start, it differs depending on what system you're using and how it's configured and whether you send directly to the recipient or to your ISP's mailserver, etc. In C# (which only works on Windows), they give you a nice one-liner. C++ does not, and will not, ever have one because you can't make it work the same across all systems.
I advise you write your spammy application in another language, find a pre-written C++ library, or learn how to talk SMTP.
- Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
- A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
- The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.
Yes you do, if you want to try and send email.
I don't know C#, but the "I think" looks a little sketchy to me. Have you actually used this function to send email to another computer?I think that in C# (windows), they have a class
and It requires only to call it like :
files: MyFilesObject
and then MyFilesObject.sendFile (... filename .. )
If not, most likely you are a little confused about what's going on, etc.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
OK , I understand.In C# (which only works on Windows), they give you a nice one-liner. C++ does not, and will not, ever have one because you can't make it work the same across all systems.
So I will try another way:
I want it only windows. It is enough for my very specific case.
So I would like to call a C# method (with no parameter! )
And it will call the "files" class and method to send a file to a specific mail recipient.
No Parameters. Assume the C# knows the file name. assume it is hard coded.
assume everything is hard-coded:
the mail recipient address , say "[email protected]",
and also the local file name, say "MyTeachers.txt"
So How do I connect them ?
I will reiterate my advice:
"I advise you write your spammy application in another language, find a pre-written C++ library, or learn how to talk SMTP."
Writing the code to send an email message direct from a C++ program requires either a library that has written the code for you already (google "C++ library smtp", for instance), or you WRITING one of those yourself (effectively). I'd be impressed if you could do it reliably in under a few hundred lines of codes, just for the most basic of cases. It's not something someone is just going to knock up for you on these forums.
MIME encoding, UUencoding, SMTP, possibly TLS, certainly lots of dealing with SMTP commands that could crop up with the various servers you're sending email to, etc. You can't just "bodge" this. Find a library that does it properly, or learn how to program ALL of those things. Just a hint, the RFC for SMTP alone is about 68 pages - without a single line of code - even for a hideously out-of-date version of it, and the VMime library - the first I found on Google - is about 7 years of work and hundreds of thousands of lines of code. All that just to send an email. Now how complicated do you think that's going to be to do if you can't even google it yourself or even know what SMTP is before you started?
- Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
- A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
- The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.