Emailing

Hey, I am currently trying to make a program that will send a text to my cell phone but, I am trying to do this by sending a email to mynumber@pcs.rogers.com which is the texting address for rogers. Does anyone know how i can do such a thing. I have been googling for hours and i can't find anything.
Yes i've googled that already and iv clicked all the links. Im not sure exactly how to do this.
Really? Even http://www.cplusplus.com/forum/windows/35333/ where working code is presented near the end of the thread (non-secure SMTP's only)?
I tried that link you said and the code and this is what the output is:

220 mx.google.com ESMTP wh8sm18119467igb.11
250-mx.google.com at your service, [24.156.213.244]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
220 2.0.0 Ready to start TLS
Mail successfully sent.


After it says this i check my mail and i have nothing from it. here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
static void sendmail_write(const int  sock,const char *str,const char *arg)
 {
    char buf[4096];

    if (arg != NULL)
        snprintf(buf, sizeof(buf), str, arg);
    else
        snprintf(buf, sizeof(buf), str);

    send(sock, buf, strlen(buf), 0);

// read a reply from server
    char outbuf[1024];
    int len=recv(sock,outbuf,1024,0);
    outbuf[len]='\0';
    cout <<outbuf;


}

static int sendmail(
                const char *from,
                const char *to,
                const char *subject,
                const char *body,
                const char *hostname,
                const int   port
            ) {

    struct hostent *host;
    struct sockaddr_in saddr_in;
    int sock = 0;


    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
        return -1;
    }


    sock = socket(AF_INET, SOCK_STREAM, 0);
    host = gethostbyname(hostname);

    saddr_in.sin_family      = AF_INET;
    saddr_in.sin_port        = htons((u_short)port);
    saddr_in.sin_addr.s_addr = 0;

    memcpy((char*)&(saddr_in.sin_addr), host->h_addr, host->h_length);

    if (connect(sock, (struct sockaddr*)&saddr_in, sizeof(saddr_in)) == -1) {
        return -2;
    }



    sendmail_write(sock, "EHLO %s\n",       "Testname");  // Should I use HELO or EHLO?

    sendmail_write(sock, "STARTTLS\n",""); // <----- starting TLS?


    sendmail_write(sock, "MAIL FROM: %s\n", from);    // from
    sendmail_write(sock, "RCPT TO: %s\n",   to);      // to
    sendmail_write(sock, "DATA\n",          NULL);    // begin data
    sendmail_write(sock, "From: %s\n",      from);
    sendmail_write(sock, "To: %s\n",        to);
    sendmail_write(sock, "Subject: %s\n",   subject);
    sendmail_write(sock, "\n",              NULL);
    sendmail_write(sock, "%s\n",            body);    // data
    sendmail_write(sock, ".\n",             NULL);    // end data
    sendmail_write(sock, "QUIT\n",          NULL);    // terminate

    closesocket(sock);

    return 0;
}


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

    int ret = sendmail(

        "mack_whipp@hotmail.com",  // from - put an email address here
        "mack_whipp@hotmail.com", // to - put an email address here
        "subject_sendmail",
        "body_text",
        "smtp.gmail.com",
        25
    );

    if (ret != 0)
    {
        fprintf(stderr, "Failed to send mail (code: %i).\n", ret);
        system("pause");
        }
    else
    {
        fprintf(stdout, "Mail successfully sent.\n");
        system("pause");
        }

    return ret;
}


Do you know whats wrong?
No, sorry. But the code in that thread doesn't work with Google's SMTP servers because they require a secured connection. If you read the thread, you'll see that the original poster decided to use that code, yes, but with an SMTP server that doesn't require a secure connection, and Google servers require a secure connection.
Okay so im using a different SMTP and im running it off my local host so the bottom portion of my code is this now :

1
2
3
4
5
6
7
8
9
10
11
int main(int argc, char *argv[]) {

    int ret = sendmail(

        "mack_whipp@hotmail.com",  // from - put an email address here
        "mack_whipp@hotmail.com", // to - put an email address here
        "subject_sendmail",
        "body_text",
        "localhost",
        25
    );


It shows a connection to my mail server and i get this output:
220 localhost
250-localhost
250 HELP
500 Syntax Error
250 mack_whipp@hotmail.com Address Okay
250 mack_whipp@hotmail.com Address Okay
354 Start mail input; end with <CRLF>.<CRLF>

After this it does nothing. do you know whats wrong with it?
Topic archived. No new replies allowed.