-2

I am trying to build an automated email sender that sends ms statistics of a gameserver, and also used for notifying the server administrators about potential cheaters and problems. The server modification is currently a C++ DLL, although at some later time when I'm more experienced I intend to make a GUI dedicated server application.

The emails will be sent once every 5 hours (server administrator can change this through the configuration settings) and when a player is reported and a member is added (to gain privileges within the server).

I've had a brief look on Google and all I can find are external libraries for this. Is it possible to send the emails without additional third-party libraries? Also, would would the requirements be? The application that will be using the DLL runs on Windows Server 2008 (or Windows 7) or later and can run on a variety of internet types.

Can this be done without an SMTP server installed?

AStopher
  • 4,207
  • 11
  • 50
  • 75
  • http://stackoverflow.com/questions/5926294/how-to-send-emails-using-yahoo-or-gmail-in-c – 4pie0 Nov 20 '13 at 13:29
  • @piotruś This is with an email account on a third-party site. I need to send an email without an actual account (I know it's possible because I use it for a couple of my PHP sites). The reason for this is because many people are going to use it, and don't want to give them access to an email account they can easily lock out from others. – AStopher Nov 20 '13 at 13:36
  • 1
    no. there is example how to connect to smtp server, you just need to talk to it – 4pie0 Nov 20 '13 at 13:46
  • Yeah, I just read that :). If the other solutions don't work, I'll use this :). Thanks :). – AStopher Nov 20 '13 at 13:51

2 Answers2

1

The emails must be sent to an SMTP server, namely the SMTP server of the receiver. There are two ways to achieve this: by talking to a local SMTP server, or by acting as an SMTP server yourself.

In the latter case, you must connect to other SMTP servers, convince them you are not a spammer, and still deliver a number of emails which are automatically generated. The challenge in that should be clear(!)

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Would it work if I was to create a private account on my own domain and send the email via this account? – AStopher Nov 20 '13 at 13:42
  • 1
    Yup, because that "own domain" implies "local SMTP server installed". It will talk on your behalf to the remote SMTP server. – MSalters Nov 20 '13 at 13:47
1

one of examples:

#include<iostream>
     #include <sys/types.h>
     #include <sys/socket.h>
     #include <netinet/in.h>
     #include <netdb.h>
     #include <stdio.h>
     using namespace std;
     #define HELO "HELO 192.168.1.1\r\n"
     #define DATA "DATA\r\n"
     #define QUIT "QUIT\r\n"

    //#define h_addr h_addr_list[0]
    //FILE *fin;
    int sock;
    struct sockaddr_in server;
    struct hostent *hp, *gethostbyname();
    char buf[BUFSIZ+1];
    int len;
    char *host_id="192.168.1.10";
    char *from_id="rameshgoli@example.com";
    char *to_id="rameshgoli@example.com";
    char *sub="testmail\r\n";
    char wkstr[100]="hello how r u\r\n";

    /*=====Send a string to the socket=====*/

    void send_socket(char *s)
    {
        write(sock,s,strlen(s));
        write(1,s,strlen(s));
        //printf("Client:%s\n",s);
    }

    //=====Read a string from the socket=====*/

    void read_socket()
    {
        len = read(sock,buf,BUFSIZ);
        write(1,buf,len);
      //printf("Server:%s\n",buf);
    }

    /*=====MAIN=====*/
    int main(int argc, char* argv[])
    {

    /*=====Create Socket=====*/
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock==-1)
    {
     perror("opening stream socket");
     exit(1);
    }
    else
      cout << "socket created\n";
    /*=====Verify host=====*/
    server.sin_family = AF_INET;
    hp = gethostbyname(host_id);
    if (hp==(struct hostent *) 0)
    {
     fprintf(stderr, "%s: unknown host\n", host_id);
     exit(2);
    }

    /*=====Connect to port 25 on remote host=====*/
    memcpy((char *) &server.sin_addr, (char *) hp->h_addr, hp->h_length);
    server.sin_port=htons(25); /* SMTP PORT */
    if (connect(sock, (struct sockaddr *) &server, sizeof server)==-1)
    {
     perror("connecting stream socket");
     exit(1);
    }
    else
      cout << "Connected\n";
    /*=====Write some data then read some =====*/
    read_socket(); /* SMTP Server logon string */
    send_socket(HELO); /* introduce ourselves */
    read_socket(); /*Read reply */
    send_socket("MAIL FROM: "); 
    send_socket(from_id);
    send_socket("\r\n");
    read_socket(); /* Sender OK */
    send_socket("VRFY ");
    send_socket(from_id);
    send_socket("\r\n");
    read_socket(); // Sender OK */
    send_socket("RCPT TO: "); /*Mail to*/
    send_socket(to_id);
    send_socket("\r\n");
    read_socket(); // Recipient OK*/
    send_socket(DATA);// body to follow*/
    send_socket("Subject: ");
    send_socket(sub);
    read_socket(); // Recipient OK*/
    send_socket(wkstr);
    send_socket(".\r\n");
    read_socket(); 
    send_socket(QUIT); /* quit */
    read_socket(); // log off */

    //=====Close socket and finish=====*/
    close(sock);
    exit(0);
  }
MSalters
  • 173,980
  • 10
  • 155
  • 350
4pie0
  • 29,204
  • 9
  • 82
  • 118