how to send mails from VC++ program without using outlook
Hi everybody,
I m writting an application which calulates some results and send them thr e-mail.I want my VC++ program to send this mail to specified address without using Outlook Express or Microsoft Outlook...or without opening any browser window...in fact i want to send them undetected..that means user shud not know abt sending mails....plzzzzz anybody tell me how to do this..its urgent...do u think socket programming will do this?
thanx in advance
Re: how to send mails from VC++ program without using outlook
Well, i rly like your code but... Most servers currently need TLS/SSL support, which i do not know how to implement.
Re: how to send mails from VC++ program without using outlook
:confused:
You realise this threads over 5 years old?
Re: how to send mails from VC++ program without using outlook
Indeed.
Well, any one has tried sending emails with SMTP Authentication under VIsual C++?
It seems to be a useful feature.
The following one using visual C++ but only support the VC++ 2005 and 2008.
http://www.naughter.com/smtp.html
I like VC++ 6 better for its reliable codes and smaller code size.
Re: how to send mails from VC++ program without using outlook
"Please note that as of v2.70, the code is now for Visual C++ 2005 or later. I will not be supporting VC 6 anymore for this code, so please don't email me requesting this<gg>. Remember VC 6 is now a ten year old compiler. It's now time to upgrade to VC 2005 or VC 2008!"
Maybe someone can share the V2.70 or earlier edition while the author stopped providing aged releases.
Re: how to send mails from VC++ program without using outlook
I use this send mail vc++ code but it gives error error during call to recv<> reply:-1 - 10054 and remaing all lines.so give me solution,exactly what is the problem
Re: how to send mails from VC++ program without using outlook
I'm an old VB6 guy working my way through MSVC. At 56, it's hard to assimilate enough to write MSVC effectively before I'm retirement age! Your generous and cooperative attitude will help more people than you know. Thank you so much.
Re: how to send mails from VC++ program without using outlook
I am also having the problem with the code errors. The exact same, actually.
Re: how to send mails from VC++ program without using outlook
I m writting an application which calulates some results and send them thr e-mail.I want my VC++ program to send this mail to specified address without using Outlook Express or Microsoft Outlook...So You try to this link htttp://www.coolinterview.com
1 Attachment(s)
Re: how to send mails from VC++ program without using outlook
Please someone help me im trying 1 week to use this code.
I m getting error on this line : if(connect(hServer, (PSOCKADDR) &SockAddr, sizeof(SockAddr)))
Please see error screenshot
This is my code :
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
//#include <fstream.h>
//#include <iostream.h>
#include <windows.h>
#include <winsock2.h>
using namespace std;
#pragma comment(lib, "ws2_32.lib")
// Insist on at least Winsock v1.1
const int VERSION_MAJOR = 1;
const int VERSION_MINOR = 1;
#define CRLF "\r\n" // carriage-return/line feed pair
void ShowUsage(void)
{
cout << "Usage: SENDMAIL mailserv to_addr from_addr messagefile" << endl
<< "Example: SENDMAIL smtp.myisp.com rcvr@elsewhere.com my_id@mydomain.com message.txt" << endl;
exit(1);
}
// Basic error checking for send() and recv() functions
void Check(int iStatus, char *szFunction)
{
if((iStatus != SOCKET_ERROR) && (iStatus))
return;
cerr << "Error during call to " << szFunction << ": " << iStatus << " - " << GetLastError() << endl;
}
int main(int argc, char *argv[])
{
int iProtocolPort = 587;
char szSmtpServerName[64] = "smtp.gmail.com";
char szToAddr[64] = "lester555@gmail.com";
char szFromAddr[64] = "555lester@gmail.com";
char szBuffer[4096] = "lester555@gmail.com";
char szLine[255] = "vai vai vaiiii";
char szMsgLine[255] = "vai vai vaiiii";
SOCKET hServer;
WSADATA WSData;
LPHOSTENT lpHostEntry;
LPSERVENT lpServEntry;
SOCKADDR_IN SockAddr;
argc = 5;
// Check for four command-line args
if(argc != 5)
ShowUsage();
// Load command-line args
lstrcpy(szSmtpServerName, argv[1]);
lstrcpy(szToAddr, argv[2]);
lstrcpy(szFromAddr, argv[3]);
// Create input stream for reading email message file
string dir = "D:\\file.txt";
ifstream MsgFile(dir);
// Attempt to intialize WinSock (1.1 or later)
if(WSAStartup(MAKEWORD(VERSION_MAJOR, VERSION_MINOR), &WSData))
{
cout << "Cannot find Winsock v" << VERSION_MAJOR << "." << VERSION_MINOR << " or later!" << endl;
return 1;
}
// Lookup email server's IP address.
lpHostEntry = gethostbyname(szSmtpServerName);
if(!lpHostEntry)
{
cout << "Cannot find SMTP mail server " << szSmtpServerName << endl;
return 1;
}
// Create a TCP/IP socket, no specific protocol
hServer = socket(PF_INET, SOCK_STREAM, 0);
if(hServer == INVALID_SOCKET)
{
cout << "Cannot open mail server socket" << endl;
return 1;
}
// Get the mail service port
lpServEntry = getservbyname("mail", 0);
// Use the SMTP default port if no other port is specified
if(!lpServEntry)
iProtocolPort = htons(IPPORT_SMTP);
else
iProtocolPort = lpServEntry->s_port;
//iProtocolPort = 587;
// Setup a Socket Address structure
SockAddr.sin_family = AF_INET;
SockAddr.sin_port = iProtocolPort;
SockAddr.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
// Connect the Socket
if(connect(hServer, (PSOCKADDR) &SockAddr, sizeof(SockAddr)))
{
cout << "Error connecting to Server socket" << endl;
DWORD err = ::GetLastError();
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
cout << (LPCTSTR)lpMsgBuf << endl;
system("pause");
return 1;
}
// Receive initial response from SMTP server
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() Reply");
// Send HELO server.com
sprintf(szMsgLine, "HELO %s%s", szSmtpServerName, CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() HELO");
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() HELO");
// Send MAIL FROM: <sender@mydomain.com>
sprintf(szMsgLine, "MAIL FROM:<%s>%s", szFromAddr, CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() MAIL FROM");
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() MAIL FROM");
// Send RCPT TO: <receiver@domain.com>
sprintf(szMsgLine, "RCPT TO:<%s>%s", szToAddr, CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() RCPT TO");
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() RCPT TO");
// Send DATA
sprintf(szMsgLine, "DATA%s", CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() DATA");
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() DATA");
// Send all lines of message body (using supplied text file)
MsgFile.getline(szLine, sizeof(szLine)); // Get first line
do // for each line of message text...
{
sprintf(szMsgLine, "%s%s", szLine, CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() message-line");
MsgFile.getline(szLine, sizeof(szLine)); // get next line.
} while(MsgFile.good());
// Send blank line and a period
sprintf(szMsgLine, "%s.%s", CRLF, CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() end-message");
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() end-message");
// Send QUIT
sprintf(szMsgLine, "QUIT%s", CRLF);
Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() QUIT");
Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() QUIT");
// Report message has been sent
cout << "Sent " << argv[4] << " as email message to " << szToAddr << endl;
// Close server socket and prepare to exit.
closesocket(hServer);
WSACleanup();
return 0;
}
Re: how to send mails from VC++ program without using outlook
Hi,
I am also using this program and it works for me if I use char (ascii), but as soon as I use unicode wchar to send the subject and the body, I get an email with a blank subject and body.
Any ideas why this is happening?
Re: how to send mails from VC++ program without using outlook
Quote:
Originally Posted by
sushb4u
ok... thanx a lottt:) my prog is working now.
can i give any points or like something that??i m new to this forum...thats why i m asking this.
Would you mind posting the code you used with notes where you made changes? I'm new to this and need a little bit more information...