I know this is probably a stupid question, but I've been looking for tutorials and examples and all I get are nefarious ways to send keyloggers or something dumb like "How to email your C++ code".
All I want is to send a an email to a user based on their given email with a message based on a string variable. No strings attached. Something like this would be suitable.
1 2 3 4 5 6 7 8 9
int main() {
string email;
string message;
cout << "What's your email?" << endl;
cin >> email;
cout << "What message do you want to send?" << endl;
getline(cin, message);
//send the message to the given email
}
At some point I'd like to create an email verification system before I start sending emails to any address the user gives me, but for now I'd just like to create a basic code that can send emails. Thank you.
Welcome to the world of 3rd-party libaries. C++ itself doesn't have built-in functionality for email, so you need to either implement it yourself (HARD, don't waste your time learning email protocols), or use a library to help you. cURL can do that.
Yep, you'll need to build the library on your system, and then link your code to it.
I have not built libcurl but try reading through it. It will probably seem complicated if you've never done something like this before. If you're on Windows, I personally I find it the easiest to build these sorts of libraries using MSYS2, but you don't need it.
no, your code can be wherever. Just need to get the paths right for #includes and library objects in your compile.
on Linux, something like system "mail -s "Test Subject" user@example.com < /dev/null" can be rigged up as well, for the cheesy get it done approach. Not the best approach to everything, but its 'an' answer to the problem. Ive used this to alert myself when something had a problem.