-
February 26th, 2004, 10:46 PM
#1
sending mails without using outlook
Hey guys,
i am wrking on creating an anonymous mailer which could be used to send mails to anyone i.e to web-based like yahoo nd other smtp servers with customised from field. How can i do that. i looked at mapi api's but i cudnt get any solid help. all they want is a session with outlook. which i dont want to. any type of help will be appreciated
"I came"
"I saw"
"I conquered"
-
February 26th, 2004, 11:15 PM
#2
i found this link on code guru
http://www.codeguru.com/forum/showth...c&pagenumber=1
but i coudnt understand the code extract completely.
typedef ULONG (FAR PASCAL *PFN_MAPILogon)(ULONG,LPTSTR,LPTSTR,FLAGS,ULONG,LPLHANDLE);
wat does this mean
i know wat typedef is but wats is with this brackets nd all those commas(,). can anyone please explain
Thanx in advance
Last edited by Cyber Bandit; February 26th, 2004 at 11:23 PM.
"I came"
"I saw"
"I conquered"
-
February 27th, 2004, 02:12 AM
#3
I had a similar need in an app I wrote. There are a number of ways you can go about it -- the .NET framework has built in functionality, you can buy a third party package, or there are a number of free packages on the internet. Since I was writing an MFC app the .NET soln was not appropriate (and it was actually quite limited) and I didn't want to buy anything, so I found a good free package: CSMTPConnection v 2.39
-Frank
-
February 27th, 2004, 04:44 AM
#4
Originally posted by Cyber Bandit
but i coudnt understand the code extract completely.
typedef ULONG (FAR PASCAL *PFN_MAPILogon)(ULONG,LPTSTR,LPTSTR,FLAGS,ULONG,LPLHANDLE);
wat does this mean
It is a function pointer definition...
-
February 27th, 2004, 04:45 AM
#5
The following is a simple console application which sends an email...
Code:
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <windows.h>
#include <winsock2.h>
// Add 'ws2_32.lib' to your linker options
// Insist on at least Winsock v1.1
const VERSION_MAJOR = 1;
const 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 = 0;
char szSmtpServerName[64] = "";
char szToAddr[64] = "";
char szFromAddr[64] = "";
char szBuffer[4096] = "";
char szLine[255] = "";
char szMsgLine[255] = "";
SOCKET hServer;
WSADATA WSData;
LPHOSTENT lpHostEntry;
LPSERVENT lpServEntry;
SOCKADDR_IN SockAddr;
// 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
ifstream MsgFile(argv[4]);
// 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;
// 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;
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;
}
Attachments need to be sent by encoding the message in MIME format. You can find the RFC at http://www.nacs.uci.edu/indiv/ehood...45/rfc2045.html for example.
Additionally you might take a look at http://codeproject.com/internet/csmtpconn.asp. It wraps the SMTP protocol including the mentioned MIME attachments...
-
March 6th, 2004, 12:21 PM
#6
i looked at all the above given stuff. but all of them require at least one or other thing. for e.g. the Mapi requires microsoft outlook nd the smtp one wants the address of some smtp server.
wat i want is totally independent solution. maybe i need is to create a smtp server r something like that. but i cudnt get any help on how to do that. i even looked at RFC 821 but it gives the technique to communicate with the smtp server. nd not how to send mail frm its own.
the csmtp class stated above also needs to know a smtp server address.
can anyone refer some documentation r RFC frm where i can get that help nd also tell me how to communicate with web based mails such as yahoo. that is how to send mails to them frm smtp server. i cudnt get hold of any RFC stating that.
thanx in advance.
Regards,
Bandit
"I came"
"I saw"
"I conquered"
-
March 6th, 2004, 01:04 PM
#7
I am not sure whether I understood correctly what RFC you are looking for but...
-
March 6th, 2004, 01:39 PM
#8
well Andreas Masur,
i have looked at RFC 821 but it is how to communicate with smtp server that is how to send mail through smtp server. wat i want is how to send mail without even using smtp server. may be how to create a smtp server nd how to use it etc.
"I came"
"I saw"
"I conquered"
-
March 6th, 2004, 02:50 PM
#9
Well...SMTP is the standard mail protocol...if you want to send something like a 'mail' (a message) then you can define your own protocol (which might for example only send some lines with text, no header etc.). In this case you simply have to create a client and a server which understand your protocol.
However, my question would rather be...why?
-
March 7th, 2004, 12:36 PM
#10
Well Andreas. m not talking bout some general messaging service. can u give me some idea say how to create a smtp server nd how to make it communicate with other servers say other smtp servers r web based mail servers.
"I came"
"I saw"
"I conquered"
-
March 7th, 2004, 01:37 PM
#11
Did I understand that right: You want to create a mail server. And you want to know how you must "talk" with other servers to "send" an email you got by a client?
-
March 7th, 2004, 04:00 PM
#12
Originally posted by Cyber Bandit
Well Andreas. m not talking bout some general messaging service. can u give me some idea say how to create a smtp server nd how to make it communicate with other servers say other smtp servers r web based mail servers.
Well...although you might hate me now...by implementing the SMTP protocol...
However, there exists already some SMTP classes like this one...
-
March 8th, 2004, 12:23 PM
#13
man this aint wat i want. this implementation is not wat i want. the csmtp class requires u to have some smtp server to which u connect nd than send mail through that. wat i want is that i dont have to pass through all these procedure nd send the mail directly frm the system. this is wat i want but until now i dint get a way out for this. do u have some idea bout that....
"I came"
"I saw"
"I conquered"
-
March 8th, 2004, 12:53 PM
#14
Ok now I know what you mean
You have to do following:
1. Listening at port 25 for incoming connections.
2. If someone connects you must receive the mail, sent by the client. (You can find an example for such a message in the rfc above)
3. And if the client wants to send his mail to someone@gmx.at (for example) you must connect to the smtp server "gmx.at" and give him the mail (and this server will store the mail localy for the account) ...
but take a look at the rfc above ...
this is what a mail server does ...
Any questions left?
-
March 8th, 2004, 01:36 PM
#15
Originally posted by Cyber Bandit
man this aint wat i want. this implementation is not wat i want. the csmtp class requires u to have some smtp server to which u connect nd than send mail through that. wat i want is that i dont have to pass through all these procedure nd send the mail directly frm the system. this is wat i want but until now i dint get a way out for this. do u have some idea bout that....
Well...I then still might not understand your actual problem and thus cannot help much more. The above posted example application shows how to send a mail. Mails are being exchanged by implementing the SMTP protocol. There is no other way around. If you do not want to do it, you have to define your own protocol and simply exchange your messages using this protocol...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|