SFML community forums

Help => Network => Topic started by: Niely on February 28, 2015, 04:42:26 pm

Title: Sending mails using SFML
Post by: Niely on February 28, 2015, 04:42:26 pm
Hello

Does someone know how to send a mail with SFML C++?
My idea was to use TCP sockets, and send SMTP commands to the SMTP-server; but it ain't working.

This is my code:
sf::TcpSocket socket;
sf::Packet packet;

socket.send("smtp.gmail.com", 587);

packet << "Hi there!";
socket.send(packet);
packet.clear();

packet << "MAIL FROM: mymail@mail.com";
socket.send(packet);
packet.clear();

packet << "RCPT TO: mymail@mail.com";
socket.send(packet);
packet.clear();

packet << "DATA";
socket.send(packet);
packet.clear();

packet << "Message2";
socket.send(packet);
packet.clear();

packet << ".";
socket.send(packet);
packet.clear();

packet << "QUIT";
socket.send(packet);
packet.clear();
 

I get no compiling error, but I just don't receive a mail.

Thanks for reading,
Niely
Title: Re: Sending mails using SFML
Post by: zsbzsb on February 28, 2015, 04:53:17 pm
Quote
but I just don't receive a mail.

Because google's servers are laughing at your connection attempt (there isn't even a connection opened). All I can say is, you got a long way to go and I wouldn't suggest you trying to do this yourself. Instead go find some other library to do this for you.

http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol
https://www.ietf.org/rfc/rfc2821.txt
https://tools.ietf.org/html/rfc821
Title: Re: Sending mails using SFML
Post by: Jesper Juhl on February 28, 2015, 05:17:59 pm
SFML does not contain any SMTP specific functionality. You'd have to use raw sockets and manage the SMTP bits yourself - or, as mentioned above, use a different lib for the mail bits or just call out to some external program like mailx, sendmail or similar.
And btw; just because code compiles doesn't mean it will do what you want - not even close.
Title: Re: Sending mails using SFML
Post by: Laurent on February 28, 2015, 05:37:35 pm
1. Connect your socket (RTFM!)
2. Don't use packets, they have their own internal protocol that Google doesn't know about
3. Use port 25

Then it should work, it's pretty straight-forward to have basic e-mail functionality. For a full client though it's a little more complicated, especially if you want a secured connection.