Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sending mails using SFML  (Read 2640 times)

0 Members and 1 Guest are viewing this topic.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Sending mails using SFML
« 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

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sending mails using SFML
« Reply #1 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
« Last Edit: February 28, 2015, 05:00:30 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Sending mails using SFML
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sending mails using SFML
« Reply #3 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.
Laurent Gomila - SFML developer