Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

(C++) Send Email

Featured Replies

Posted

Hi,

so, i``m trying to send an email from one gmail acc. to another using winosck:

Code looks good, google is "at my service", but the email never arrives. :teehee:


#include "stdafx.h"
#include <winsock2.h>
#include <string>
#include <stdlib.h>
#include <iostream>
using namespace std;#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "urlmon.lib")
#pragma comment(lib, "shell32.lib")
int main()
{
int iProtocolPort = 0;
char szBuffer[4096] = "";
SOCKET hServer;
LPHOSTENT lpHostEntry;
LPSERVENT lpServEntry;
SOCKADDR_IN SockAddr; WSADATA WSAData;
DWORD WSAResult; WSAResult = WSAStartup(MAKEWORD(2,2), &WSAData); //lookup SMTP server's IP address
lpHostEntry = gethostbyname("smtp.gmail.com"); if(!lpHostEntry)
{
// SMTP server not found!
return false;
} // create a TCP/IP socket, no specific protocol
hServer = socket(PF_INET, SOCK_STREAM, 0);
if (hServer == INVALID_SOCKET)
return false;//connection failed SockAddr.sin_family = AF_INET;
SockAddr.sin_port = htons(25);//iProtocolPort;
SockAddr.sin_addr = *((LPIN_ADDR) *lpHostEntry->h_addr_list); // connect the Socket
if(connect(hServer, (PSOCKADDR) &SockAddr, sizeof(SockAddr)))
return false;//connection failed .)
// receive initial response from SMTP server
recv(hServer, szBuffer, sizeof(szBuffer), 0); // send HELO smtp_server.com
sprintf(szBuffer, "HELO %s\r\n", "smtp.gmail.com");//SMTP
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); //###### sprintf(szBuffer,"ehlo\r\n");
send(hServer,szBuffer,strlen(szBuffer),0);
recv(hServer,szBuffer,sizeof(szBuffer),0);
strcpy(szBuffer, "STARTTLS\r\n");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0);
// Sending login request
strcpy(szBuffer, "auth login\r\n");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); // Send userid
sprintf(szBuffer,"%s\r\n", "base64(a2@gmail.com");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0);
// Send Pwd
sprintf(szBuffer,"%s\r\n", "base64(password)");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); //######
// send From
sprintf(szBuffer, "MAIL FROM:<%s>\r\n", "a2@gmail.com");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); // Send To
sprintf(szBuffer, "RCPT TO:<%s>\r\n", "a1@gmail.com");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); // Send Data
sprintf(szBuffer, "DATA\r\n");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0);
// Setting Subject and Body
sprintf(szBuffer,"Subject: %s\r\n\r\n%s\r\n.\r\n","subject", "msgmsgmsg"); //message & subject send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0);//blank line to end
sprintf(szBuffer, "");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); // Sending end command
sprintf(szBuffer, "quit\r\n");
send(hServer, szBuffer, strlen(szBuffer), 0);
recv(hServer, szBuffer, sizeof(szBuffer), 0); // clean up - close server socket
closesocket(hServer); return true;
}

I base64 encode the uid and the password manually, then just use the encoded strings in the code.

Gmail states here:
/>http://mail.google.com/support/bin/answer.py?answer=78799

that i am supposed to use port 465, but then the connection fails.

Using port 25 works fine (server response: gmail is at you service).

Does anyone know what goes wrong? :)

dp0 :)

Edited by deepzero

Do you know what the command STARTTLS is doing?

  • Author

not really! :/

I was told by the gmail server to use it. :woot:

will do some more reading...

  • Author

After sending "STARTTLS" to the server i get the response:

"220 2.0.0 Ready to start TLS

ice, [%myip%]

250-SIZE 35651584

250-8BITMIME

250-STARTTLS

250 ENHANCEDSTATUSCODES

So gmail is ready to start tls, but how do i start it?

Couldnt find any info, just desperate people in other forums... :dunno:

Check this CodeProject page out, it might help with this issue:
/>http://www.codeproject.com/KB/IP/smtp_ssl.aspx

dont you think that this will not work? even old troyans that report back with ip in email to attacker dont work.

due all email connections are encrypted today and not on 25 port but 465 Secure to dedicated port(TLS).

so i think you need ssl and somehow mix it with google api.

im not expert in that field so cant tell how.

So are you trying to use TLS? I'm no expert on the protocol but just telnetting to smtp.google.com I think you can send a spoof email to yourself, try just connecting to port 25 and not sending STARTTLS and your code should work, but if you want encryption I have no idea how TLS works...lol

edit: found this project, take a look at the source: http://www.codeproject.com/KB/IP/smtp_ssl.aspx

It requires a lot of complicated header files but those are all GNU and you wont have to look at those in detail.

EDIT2: just realized this was already posted lol whatever...

Edited by Dooms_day

You can debug "Foxmail",then write your code!

You gotta use RFC 2821 protocal standards

its

HELO JMC31337

mail from:<jmc31337@gmail.com>

rcpt to:<jmc31337@gmail.com>

data

123

.

quit

then it will end up in your SPAM folder as unknown sender
/>http://www.ietf.org/rfc/rfc2821.txt

use nslookup

set type=mx

gmail.com

telnet gmail-smtp-in.l.google.com 25

now with Nemesis SMTP Worm

it'll use C# to pass a null pointer and use DEFAULT USER CREDENTIALS which uses YOUR ISP to send email making it look as though its a legit source...

client.Credentials = new System.Net.NetworkCredential(null, "");

Edited by JMC31337

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.