Code for sending an e-mail message to a pop3 server 
Author Message
 Code for sending an e-mail message to a pop3 server

Hello,

is there any sample code (32bit Windows) for sending an e-mail message to a
pop3 Server?

Thanx, RD



Mon, 26 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

In her book, Building Internet Applications with Visual C++
(ISBN-0-7897-0213-4) Kate Gregory builds a simple mail client.

Regards,
Will



Quote:
> is there any sample code (32bit Windows) for sending an e-mail message to
a
> pop3 Server?



Mon, 26 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

Should I feel honored or insulted?

Regards,
Will



Quote:

>    memset(&MapiTo[1], 0, sizeof(MapiTo[1));
>    MapiTo[1].ulRecipClass = MAPI_CC;

>    MapiTo[1].lpszName  = _T("The Little  Sleeze");



Tue, 27 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

Hi Robert,

Here is the code you need:

HINSTANCE hInstMail  = ::LoadLibraryA("MAPI32.DLL");
if (hInstMail  == NULL)
{
        AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
        return;

Quote:
}

ASSERT(hInstMail  != NULL);

ULONG (Pascal *lpfnLogon )(ULONG, LPTSTR ,
LPTSTR , FLAGS , ULONG , LPLHANDLE );
(FARPROC&)lpfnLogon = GetProcAddress(hInstMail , "MAPILogon");

LHANDLE lhSession = 0;
ULONG ul = 0;

lpfnLogon(NULL, _T("MS Exchange Settings"),
_T("YourPassword"), 0, 0, &lhSession);

        MapiRecipDesc MapiFrom;
        memset(&MapiFrom, 0, sizeof(MapiFrom));
        MapiFrom.ulRecipClass = MAPI_ORIG;
        MapiFrom.lpszName = _T("Someone");

        apiRecipDesc MapiTo[2];

        memset(&MapiTo[0], 0, sizeof(MapiTo[0]));
        MapiTo[0].ulRecipClass = MAPI_TO;

        MapiTo[0].lpszName  = _T("The Big Cheese");

        memset(&MapiTo[1], 0, sizeof(MapiTo[1));
        MapiTo[1].ulRecipClass = MAPI_CC;

        MapiTo[1].lpszName  = _T("The Little  Sleeze");

        CString subject = _T("Hello");
        CString text = _T("\n\nDear Whoever,\n\nGoodbye");

        MapiMessage mapimsg;
        memset(&mapimsg, 0, sizeof(mapimsg));
        mapimsg.lpszSubject = subject.GetBuffer(subject.GetLength());
        mapimsg.lpszNoteText = text.GetBuffer(text.GetLength());
        mapimsg.lpOriginator = &MapiFrom;
        mapimsg.lpRecips= MapiTo;
        mapimsg.nRecipCount= 2;

ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS,
ULONG);
        (FARPROC&)lpfnSendMail = GetProcAddress(hInstMail  ,
"MAPISendMail");
        if (lpfnSendMail == NULL)
        {
                AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
                return;
        }

ul = lpfnSendMail (lhSession,
                0,
                &mapimsg,
                 0,0);
if (ul == SUCCESS_SUCCESS)
        AfxMessageBox(_T("Message Sent successfully"));

if (hInstMail  != NULL)
                ::FreeLibrary(hInstMail );

        ul = lpfnSendMail (lhSession,
                0,
                &mapimsg,
                 0,0);

ULONG (PASCAL *lpfnLogoff)(LHANDLE , ULONG , FLAGS , ULONG );
                        (FARPROC&)lpfnLogoff =
GetProcAddress(hInstMail  , "MAPILogoff");

ul= lpfnLogoff(lhSession, 0, 0, 0);

Quote:
}

Charles Steinhardt[MVP]


Wed, 28 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

Quote:

> Hello,

> is there any sample code (32bit Windows) for sending an e-mail message to a
> pop3 Server?

> Thanx, RD

Hi Robert,

I've attached the POP3 protocol in this text file. It tells you all the
commands you can send to any POP3 server and what they're replies will
be if it was successful or an error etc.

Hope this helps,
Shezan.

[ rfc1939 POP3.txt 45K ]
Network Working Group                                           J. Myers
Request for Comments: 1939                               Carnegie Mellon
STD: 53                                                          M. Rose
Obsoletes: 1725                             Dover Beach Consulting, Inc.
Category: Standards Track                                       May 1996

                    Post Office Protocol - Version 3

Status of this Memo

   This document specifies an Internet standards track protocol for the
   Internet community, and requests discussion and suggestions for
   improvements.  Please refer to the current edition of the "Internet
   Official Protocol Standards" (STD 1) for the standardization state
   and status of this protocol.  Distribution of this memo is unlimited.

Table of Contents

   1. Introduction ................................................    2
   2. A Short Digression ..........................................    2
   3. Basic Operation .............................................    3
   4. The AUTHORIZATION State .....................................    4
      QUIT Command ................................................    5
   5. The TRANSACTION State .......................................    5
      STAT Command ................................................    6
      LIST Command ................................................    6
      RETR Command ................................................    8
      DELE Command ................................................    8
      NOOP Command ................................................    9
      RSET Command ................................................    9
   6. The UPDATE State ............................................   10
      QUIT Command ................................................   10
   7. Optional POP3 Commands ......................................   11
      TOP Command .................................................   11
      UIDL Command ................................................   12
      USER Command ................................................   13
      PASS Command ................................................   14
      APOP Command ................................................   15
   8. Scaling and Operational Considerations ......................   16
   9. POP3 Command Summary ........................................   18
   10. Example POP3 Session .......................................   19
   11. Message Format .............................................   19
   12. References .................................................   20
   13. Security Considerations ....................................   20
   14. Acknowledgements ...........................................   20
   15. Authors' Addresses .........................................   21
   Appendix A. Differences from RFC 1725 ..........................   22

Myers & Rose                Standards Track                     [Page 1]

RFC 1939                          POP3                          May 1996

   Appendix B. Command Index ......................................   23

1. Introduction

   On certain types of smaller nodes in the Internet it is often
   impractical to maintain a message transport system (MTS).  For
   example, a workstation may not have sufficient resources (cycles,
   disk space) in order to permit a SMTP server [RFC821] and associated
   local mail delivery system to be kept resident and continuously
   running.  Similarly, it may be expensive (or impossible) to keep a
   personal computer interconnected to an IP-style network for long
   amounts of time (the node is lacking the resource known as
   "connectivity").

   Despite this, it is often very useful to be able to manage mail on
   these smaller nodes, and they often support a user agent (UA) to aid
   the tasks of mail handling.  To solve this problem, a node which can
   support an MTS entity offers a maildrop service to these less endowed

   nodes.  The Post Office Protocol - Version 3 (POP3) is intended to
   permit a workstation to dynamically access a maildrop on a server
   host in a useful fashion.  Usually, this means that the POP3 protocol
   is used to allow a workstation to retrieve mail that the server is
   holding for it.

   POP3 is not intended to provide extensive manipulation operations of
   mail on the server; normally, mail is downloaded and then deleted.  A
   more advanced (and complex) protocol, IMAP4, is discussed in
   [RFC1730].

   For the remainder of this memo, the term "client host" refers to a
   host making use of the POP3 service, while the term "server host"
   refers to a host which offers the POP3 service.

2. A Short Digression

   This memo does not specify how a client host enters mail into the
   transport system, although a method consistent with the philosophy of
   this memo is presented here:

      When the user agent on a client host wishes to enter a message
      into the transport system, it establishes an SMTP connection to
      its relay host and sends all mail to it.  This relay host could
      be, but need not be, the POP3 server host for the client host.  Of
      course, the relay host must accept mail for delivery to arbitrary
      recipient addresses, that functionality is not required of all
      SMTP servers.

Myers & Rose                Standards Track                     [Page 2]

RFC 1939                          POP3                          May 1996

3. Basic Operation

   Initially, the server host starts the POP3 service by listening on
   TCP port 110.  When a client host wishes to make use of the service,
   it establishes a TCP connection with the server host.  When the
   connection is established, the POP3 server sends a greeting.  The
   client and POP3 server then exchange commands and responses
   (respectively) until the connection is closed or aborted.

   Commands in the POP3 consist of a case-insensitive keyword, possibly
   followed by one or more arguments.  All commands are terminated by a
   CRLF pair.  Keywords and arguments consist of printable ASCII
   characters.  Keywords and arguments are each separated by a single
   SPACE character.  Keywords are three or four characters long. Each
   argument may be up to 40 characters long.

   Responses in the POP3 consist of a status indicator and a keyword
   possibly followed by additional information.  All responses are
   terminated by a CRLF pair.  Responses may be up to 512 characters
   long, including the terminating CRLF.  There are currently two status
   indicators: positive ("+OK") and negative ("-ERR").  Servers MUST
   send the "+OK" and "-ERR" in upper case.

   Responses to certain commands are multi-line.  In these cases, which
   are clearly indicated below, after sending the first line of the
   response and a CRLF, any additional lines are sent, each terminated
   by a CRLF pair.  When all lines of the response have been sent, a
   final line is sent, consisting of a termination octet (decimal code
   046, ".") and a CRLF pair.  If any line of the multi-line response
   begins with the termination octet, the line is "byte-stuffed" by
   pre-pending the termination octet to that line of the response.
   Hence a multi-line response is terminated with the five octets
   "CRLF.CRLF".  When examining a multi-line response, the client checks
   to see if the line begins with the termination octet.  If so and if
   octets other than CRLF follow, the first octet of the line (the
   termination octet) is stripped away.  If so and if CRLF immediately
   follows the termination character, then the response from the POP
   server is ended and the line containing ".CRLF" is not considered
   part of the multi-line response.

   A POP3 session progresses through a number of states during its
   lifetime.  Once the TCP connection has been opened and the POP3
   server has sent the greeting, the session enters the AUTHORIZATION
   state.  In this state, the client must identify itself to the POP3
   server.  Once the client has successfully done this, the server
   acquires resources associated with the client's maildrop, and the
   session enters the TRANSACTION state.  In this state, the client
   requests actions on the part of the POP3 server.  When the client has

Myers & Rose                Standards Track                     [Page 3]

RFC 1939                          POP3                          May 1996

   issued the QUIT command, the session enters the UPDATE state.  In
   this state, the POP3 server releases any resources acquired during
   the TRANSACTION state and says goodbye.  The TCP connection is then
   closed.

   A server MUST respond to an unrecognized, unimplemented, or
   syntactically invalid command by responding with a negative status
   indicator.  A server MUST respond to a command issued when the
   session is in an incorrect state by responding with a negative status
   indicator.  There is no general method for a client to distinguish
   between a server which does not implement an optional command and a
   server which is unwilling or unable to process the command.

   A POP3 server MAY have an inactivity autologout timer.  Such a timer
   MUST be of at least 10 minutes' duration.  The receipt of any command
   from the client during that interval should suffice to reset the
   autologout timer.  When the timer expires, the session does NOT enter
   the UPDATE state--the server should close the TCP connection without
   removing any messages or sending any response to the client.

4. The AUTHORIZATION State

   Once the TCP connection has been opened by a POP3 client, the POP3
   server issues a one line greeting.  This can be any positive
   response.  An example might be:

      S:  +OK POP3 server ready

   The POP3 session is now in the AUTHORIZATION state.  The client must
   now identify and authenticate itself to
...

read more »



Thu, 29 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server


Quote:
> is there any sample code (32bit Windows) for sending an e-mail message to a
> pop3 Server?

You can't. POP3 is for retrieving mail only. You have to use SMTP or  
IMAP to send mail

--
Claus Andr F?rber <http://www.muc.de/~cfaerber/> Fax: +49_8061_3361
PGP: ID=1024/527CADCD FP=12 20 49 F3 E1 04 9E 9E  25 56 69 A5 C6 A0 C9 DC



Thu, 29 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server


Quote:
>Hello,

>is there any sample code (32bit Windows) for sending an e-mail message to a
>pop3 Server?

>Thanx, RD

You can't send email using POP3 server (protocol), you should use SMTP
protocol instead.

-------------
Martin Vladic



Fri, 30 Jun 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

Fellas,

SMTP is for sending mail and POP3 is for receiving.  I'd say look up the
RFC for SMTP/POP3 on Metacrawler or something.  You can use telnet to
log into a mail server and try typing in the commands listed in the
RFC.  I've put some clunky code in the thread below this for SMTP if
that helps.

Good luck.

Rob Knapp



Sat, 01 Jul 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

Here is that clunky SMTP code...

// MailGetter.cpp: implementation of the CMailGetter class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AutoMail.h"
#include "MailGetter.h"
#include "stdlib.h"
#include "afxsock.h"
#include "afx.h"
#include "io.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMailGetter::CMailGetter()
{      

Quote:
}

CMailGetter::~CMailGetter()
{

Quote:
}

bool CMailGetter::CheckRet(CString SMTPRet)
{
        CString Prefix = "000";
        Prefix = SMTPRet.Left(3);
        if (Prefix == "250")
                return TRUE;
        if (Prefix == "354")
                return TRUE;
        else
                return FALSE;

Quote:
}

bool CMailGetter::GetMail(CString EmailFileNameOld)
{
    int rc, errnum = 0;
        bool flag = FALSE;
        LPCTSTR MailHost;
        WSADATA wsdata;
    WORD    wVersionRequested;

    /*
    *   Initialize with the WINSOCK library  
    */
    wVersionRequested = MAKEWORD(1,1);
    rc = WSAStartup(wVersionRequested, &wsdata);

    if (rc) {
        return 0;
                }
                CSocket sock;
                sock.Create();
                MailHost = "yourmailhost.com";
                BOOL IsConnected = sock.Connect(MailHost, 25);
                if (IsConnected != TRUE)
                {       errnum = sock.GetLastError();
                        ::MessageBox(NULL, "Error Number: " + errnum, "CAsyncSocket.Connect",
MB_OK | MB_ICONEXCLAMATION);
                }
                CSocketFile file (&sock);
                CArchive arOut(&file, CArchive::store);
                CArchive arIn(&file, CArchive::load);

//////////////////////////////////////////////////////////////////////////////////////////////
        ///  *******    FILE OUTPUT TEST    *******

                char* pszFileName = "c:\\test\\Mail_File.dat";
                CFile TestFile;
                CFileException fileException;

                if ( !TestFile.Open( pszFileName, CFile::modeCreate |  
                                  CFile::modeReadWrite ), &fileException )
                {
                        TRACE( "Can't open file %s, error = %u\n",
                                pszFileName, fileException.m_cause );
                }
                CArchive arOutFile(&TestFile, CArchive::store);  

        ////////////////*****     Initalize file to open and send  **********
        char* EmailFileName = "c:\\test\\Test.dat"; //97081116.sao
        CFile InFile;
        int InFileHand = 0;
                if ( ! (InFileHand = InFile.Open(EmailFileName, CFile::modeRead)),
&fileException )
                {
                        TRACE( "Can't open file %s, error = %u\n",
                                EmailFileName, fileException.m_cause );
                }
                //CArchive arInDataFile(&InFile, CArchive::Read);
        ///

//////////////////////////////////////////////////////////////////////////////////////////////

        char aChar;
        char LongChar[256];
        CString InString, OutString, HELO, MAIL, RCPT, SUBJ, SUB;
        CString Ret = "\r\n.\r\n";
        CString CR = "\r\n";
        bool RetFlag;
        int L, c;

        HELO = "HELO yourloggin" + CR;
        MAIL = "MAIL FROM: yourloggin" + CR;

        SUB ="SUBJ: ";
        SUBJ = SUB + "This is a test!" + CR;

        do {
        arIn >> aChar;
        } while (aChar != '\r');

///  -->  Send out the HELO to the mail server
        arOut << HELO;
        arOutFile << HELO;
        arOut.Flush();
        c = 0;
        do {                                    //   Read the respsonse
        arIn >> aChar;
        if ( (aChar != '\r') && (aChar != '\n') )
                {
                        LongChar[c] = aChar;
                        ++c;
                }
        } while (aChar != '\r');
        InString = LongChar;
        RetFlag = CheckRet(InString);   // Sends it off to be checked for a
good response.
        if (RetFlag == FALSE)
                ::MessageBox(NULL, InString, "Email Services", MB_OK |
MB_ICONEXCLAMATION);

        // --->   Set Mail From:    <---
        L = MAIL.GetLength();
        for (c = 0; c < L; ++c)
        {
                aChar = MAIL.GetAt(c );
                arOut << aChar;
                arOutFile << aChar;
        }
        arOut.Flush();
        c = 0;
        do {
        arIn >> aChar;
        if ( (aChar != '\r') && (aChar != '\n') )
                {
                        LongChar[c] = aChar;
                        ++c;
                }
        } while (aChar != '\r');
        InString = LongChar;
        RetFlag = CheckRet(InString);
        if (RetFlag == FALSE)
                ::MessageBox(NULL, InString, "Email Services", MB_OK |
MB_ICONEXCLAMATION);
// ---> end set mail from <--- //
/// --> Set Recipient at mailhost <--- ///
        L = RCPT.GetLength();
        for (c = 0; c < L; ++c)
        {
                aChar = RCPT.GetAt(c );
                arOut << aChar;
                arOutFile << aChar;
        }
        arOut.Flush();
        c = 0;
        do {
        arIn >> aChar;
        if ( (aChar != '\r') && (aChar != '\n') )
                {
                        LongChar[c] = aChar;
                        ++c;
                }
        } while (aChar != '\r');
        InString = LongChar;
        RetFlag = CheckRet(InString);
        if (RetFlag == FALSE)
                ::MessageBox(NULL, InString, "Email Services", MB_OK |
MB_ICONEXCLAMATION);
/// ---> Set DATA and add SUBJ that was set above <--- ///
        OutString ="DATA \r\n" + SUBJ;
        L = OutString.GetLength();
        for (c = 0; c < L; ++c)
        {
                aChar = OutString.GetAt(c );
                arOut << aChar;
                arOutFile << aChar;
        }
        arOut.Flush();
        c = 0;
        do {
        arIn >> aChar;
        if ( (aChar != '\r') && (aChar != '\n') )
                {
                        LongChar[c] = aChar;
                        ++c;
                }
        } while (aChar != '\r');
        InString = LongChar;
        RetFlag = CheckRet(InString);
        if (RetFlag == FALSE)
                ::MessageBox(NULL, InString, "Email Services", MB_OK |
MB_ICONEXCLAMATION);

        //  **  Send Data File from HD  **  //
        char outChar[2] = {1, 2};
        DWORD FileLength = InFile.SeekToEnd();
        InFile.SeekToBegin();
        DWORD Counter = 0;
         do      {
                InFile.Read(outChar, 1);
                arOut << outChar[0];
                arOutFile << outChar[0];
                ++Counter;
        }       while (Counter < FileLength);
        arOut << Ret;   // This is "\r\n.\r\n"
        arOutFile << Ret;
        arOut.Flush();
///--->      End Data File Tansmission   <---///
/// ***  Send quit message ***  ///
        OutString ="quit \r\n";
        arOut << OutString;
        arOutFile << OutString;
        arOut.Flush();
        arIn >> InString;
        CheckRet(InString);

        ::MessageBox(NULL, "Test mail has been sent!", "Email Services", MB_OK
| MB_ICONEXCLAMATION);

return TRUE;

Quote:
}



Sat, 01 Jul 2000 03:00:00 GMT  
 Code for sending an e-mail message to a pop3 server

Robert,

Catalyst has a POP3 control included in our internet suite SocketTools. The
free evaluation software has a VB sample (STMAIL) which demonstrates how to
use the control. The software can be downloaded at our web site
(www.catalyst.com).

--
Jack Kemp - Technical Support Specialist
Catalyst Development Corp.    URL: www.catalyst.com
Download our Full Featured Evaluation copy of SocketTools
with 19 custom controls for Internet development

Quote:
>Hello,

>is there any sample code (32bit Windows) for sending an e-mail message to a
>pop3 Server?

>Thanx, RD



Sat, 01 Jul 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. SMTP Sample code (was: Code for sending an e-mail message to a pop3 server)

2. SMTP Sample code (was: Code for sending an e-mail message to a pop3 server)

3. Code for sending an e-mail message to a pop3 server

4. how to fetch emails from pop3 server??

5. Help Needed in Reading Mails from POP3 and NNTP server

6. New Mail Account in a POP3 Server

7. Mail, SMTP and POP3 servers

8. Sending mail with MAPI with out displaying send mail dialog

9. how I can get email list from mail server

10. How to send email using smtp server.(Problem)

11. How to send email without smtp server.

12. C#: Sending Lotus Notes email messages

 

 
Powered by phpBB® Forum Software