CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

请教:发邮件的VC++6.0代码?

楼主haidong()2000-02-23 19:27:00 在 VC/MFC / 基础类 提问

问题点数:30、回复次数:2Top

1 楼zjy()回复于 2000-02-23 19:48:00 得分 20

I'll   send   to   your   mail-box.  
  Top

2 楼jamesw(老唐)回复于 2000-02-24 09:44:00 得分 10

////////////////////////////////////////////////////////////////////  
  //  
  //   CRobotMail.h   -   CRobotMail   class   declarations  
  //  
  //   Source:   "Programming   Bots,   Spiders,   and   Intelligent   Agents  
  //                     in   Microsoft   Visual   C++"  
  //  
  //   Copyright   (c)   1999,   David   Pallmann.   All   rights   reserved.  
   
  #include   <mapi.h>  
   
  class   CRobotMail  
  {  
  public:  
  CRobotMail();  
  int   GetNewMessageCount();  
  int   GetMessageCount();  
  BOOL   FirstNewMessage(BOOL   bMarkAsRead   =   false);  
  BOOL   FirstMessage(BOOL   bMarkAsRead   =   false);  
  BOOL   NextMessage(BOOL   bMarkAsRead   =   false);  
  BOOL   SendMessage(CString   sTo,  
    CString   sSubject,  
    CString   sMessage,  
    CString   sAttachment);  
  ~CRobotMail();  
   
  public:  
  CString   m_sFrom;  
  CString   m_sFromAddress;  
  CString   m_sSubject;  
  CString   m_sMessage;  
  CString   m_sDate;  
  BOOL   m_bRead;  
   
  private:  
  BOOL   m_bInitialized;  
  BOOL   m_bNewOnly;  
  HINSTANCE   m_hInstMail;  
  ULONG   m_lhSession; //   LHANDLE  
   
  private:  
  char   m_pMessageID[513];  
  MapiMessage   m_message;  
  MapiMessage   *m_pMessage;  
  };  
   
   
  ////////////////////////////////////////////////////////////////////  
  //  
  //   CRobotMail.cpp   -   CRobotMail   class   implementation  
  //  
  //   Source:   "Programming   Bots,   Spiders,   and   Intelligent   Agents  
  //                     in   Microsoft   Visual   C++"  
  //  
  //   Copyright   (c)   1999,   David   Pallmann.   All   rights   reserved.  
   
  #include   <stdafx.h>  
  #include   <mapi.h>  
  #include   "CRobotMail.h"  
   
   
  //   *************************  
  //   *     MAPI   function   calls     *  
  //   *************************  
   
  ULONG   (PASCAL   *lpfnMAPISendMail)(ULONG,  
    ULONG,  
    MapiMessage*,  
    FLAGS,  
    ULONG);  
  ULONG   (PASCAL   *lpfnMAPIResolveName)(LHANDLE,  
  ULONG,  
  LPTSTR,  
  FLAGS,  
  ULONG,  
  MapiRecipDesc   **);  
  ULONG   (FAR   PASCAL   *lpfnMAPILogon)(ULONG,  
      LPSTR,  
      LPSTR,  
      FLAGS,  
      ULONG,  
      LPLHANDLE);  
  ULONG   (FAR   PASCAL   *lpfnMAPILogoff)(LHANDLE,   ULONG,   FLAGS,   ULONG);  
  ULONG   (FAR   PASCAL   *lpfnMAPIFreeBuffer)(LPVOID);  
  ULONG   (FAR   PASCAL   *lpfnMAPIAddress)(LHANDLE,  
  ULONG,  
  LPSTR,  
  ULONG,  
  LPSTR,  
  ULONG,  
  MapiRecipDesc   *,  
  FLAGS,  
  ULONG,  
  LPULONG,  
  MapiRecipDesc   **);  
  ULONG   (FAR   PASCAL   *lpfnMAPIFindNext)(LHANDLE,  
    ULONG,  
    LPSTR,  
    LPSTR,  
    FLAGS,  
    ULONG,  
    LPSTR);  
  ULONG   (FAR   PASCAL   *lpfnMAPIReadMail)(LHANDLE,  
    ULONG,  
    LPSTR,  
    FLAGS,  
    ULONG,  
    lpMapiMessage   FAR   *lppMessage);  
   
   
  //   *****************  
  //   *     Constructor     *  
  //   *****************  
   
  CRobotMail::CRobotMail()  
  {  
  //   Load   Mapi32.dll   and   compute   function   addresses  
   
  m_hInstMail   =   ::LoadLibrary("Mapi32.dll");  
  if(m_hInstMail   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   unable   to   load   MAPI32.dll");  
  m_bInitialized   =   false;  
  return;  
  }   //   End   if  
   
  /*   Find   the   addresses   of   functions   and   store   them   in   function    
        pointer   variables   */  
   
  (FARPROC&)lpfnMAPILogon   =   GetProcAddress(m_hInstMail,  
    "MAPILogon");  
  if   (lpfnMAPILogon   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   could   not   find   "  
      "the   MAPILogon   function");  
  return;  
  }   //   End   if  
   
  (FARPROC&)lpfnMAPIFindNext   =   GetProcAddress(m_hInstMail,  
  "MAPIFindNext");  
  if   (lpfnMAPIFindNext   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   could   not   find   "  
      "the   MAPIFindNext   function");  
  return;  
  }   //   End   if  
   
  (FARPROC&)lpfnMAPIReadMail   =   GetProcAddress(m_hInstMail,  
  "MAPIReadMail");  
  if   (lpfnMAPIReadMail   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   could   not   find   "  
      "the   MAPIReadMail   function");  
  return;  
  }   //   End   if  
   
  (FARPROC&)lpfnMAPIFreeBuffer   =   GetProcAddress(m_hInstMail,  
      "MAPIFreeBuffer");  
  if   (lpfnMAPIFreeBuffer   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   could   not   find   "  
      "the   MAPIFreeBuffer   function");  
  return;  
  }   //   End   if  
   
  (FARPROC&)lpfnMAPIResolveName   =   GetProcAddress(m_hInstMail,  
        "MAPIResolveName");  
  if   (lpfnMAPIResolveName   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   could   not   find   "  
      "the   MAPIResolveName   function");  
  return;  
  }   //   End   if  
   
  (FARPROC&)lpfnMAPISendMail   =   GetProcAddress(m_hInstMail,  
  "MAPISendMail");  
  if   (lpfnMAPISendMail   ==   NULL)  
  {  
  AfxMessageBox("CRobotMail:   could   not   find   "  
      "the   MAPISendMail   function");  
  return;  
  }   //   End   if  
   
  //   Log   on   to   existing   session  
   
  ULONG   lResult   =   lpfnMAPILogon(0,  
      NULL,   //   sProfileName  
      NULL,   //   sPassword  
      0, //   flFlags  
      0,  
      &m_lhSession);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return; //   Logon   failed  
   
  m_bInitialized   =   true;  
  }  
   
   
  //   ************************  
  //   *                                             *  
  //   *     GetNewMessageCount     *  
  //   *                                             *  
  //   ************************  
  //   Description: Returns   a   count   of   the   number   of    
  // unread   messages   in   the   inbox  
   
  int   CRobotMail::GetNewMessageCount()  
  {  
  if   (!m_bInitialized)   return   0;  
   
  int   nCount   =   0;  
   
  //   Find   the   first   message  
   
  ULONG   lResult   =   lpfnMAPIFindNext(m_lhSession,  
    NULL,  
    NULL,  
    NULL,  
    MAPI_LONG_MSGID     and     MAPI_UNREAD_ONLY,  
    0,  
    m_pMessageID);  
  while   (lResult   ==   SUCCESS_SUCCESS)  
  {  
  nCount++;  
  lResult   =   lpfnMAPIFindNext(m_lhSession,  
        NULL,  
        NULL,  
        m_pMessageID,  
        MAPI_LONG_MSGID     and     MAPI_UNREAD_ONLY,  
        0,  
        m_pMessageID);  
  }  
   
  return   nCount;  
  }  
   
   
  //   *********************  
  //   *                                       *  
  //   *     GetMessageCount     *  
  //   *                                       *  
  //   *********************  
  //   Description: Returns   a   count   of   the   number   of   messages    
  //                             in   the   inbox   (both   read   and   unread)  
   
  int   CRobotMail::GetMessageCount()  
  {  
  if   (!m_bInitialized)   return   0;  
   
  int   nCount   =   0;  
   
  //   Find   the   first   message  
   
  ULONG   lResult   =   lpfnMAPIFindNext(m_lhSession,  
    NULL,  
    NULL,  
    NULL,  
    MAPI_LONG_MSGID,  
    0,  
    m_pMessageID);  
  while   (lResult   ==   SUCCESS_SUCCESS)  
  {  
  nCount++;  
  lResult   =   lpfnMAPIFindNext(m_lhSession,  
        NULL,  
        NULL,  
        m_pMessageID,  
        MAPI_LONG_MSGID,  
        0,  
        m_pMessageID);  
  }  
   
  return   nCount;  
  }  
   
   
  //   *********************  
  //   *                                       *  
  //   *     FirstNewMessage     *  
  //   *                                       *  
  //   *********************  
  //   Description: Moves   to   the   first   unread   message   in   the   inbox  
   
  BOOL   CRobotMail::FirstNewMessage(BOOL   bMarkAsRead)  
  {  
  if   (!m_bInitialized)   return   false;  
   
  m_bNewOnly   =   true;  
   
  //   Find   the   first   unread   message  
   
  ULONG   lResult   =   lpfnMAPIFindNext(m_lhSession,  
    NULL,  
    NULL,  
    NULL,  
    MAPI_LONG_MSGID     and     MAPI_UNREAD_ONLY,  
    0,  
    m_pMessageID);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
   
  //   Read   the   message   (that   was   found   by   MAPIFindNext)  
   
  long   nFlags   =   MAPI_SUPPRESS_ATTACH;  
  if   (!bMarkAsRead)  
  nFlags   =   nFlags     and     MAPI_PEEK;  
  lResult   =   lpfnMAPIReadMail(m_lhSession,  
        NULL,  
        m_pMessageID,  
        nFlags,  
        0,  
        &m_pMessage);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
   
  m_sFrom   =   CString(m_pMessage->lpOriginator->lpszName);  
   
  m_sFromAddress   =   CString(m_pMessage->lpOriginator->lpszAddress);  
   
  m_sDate   =   CString(m_pMessage->lpszDateReceived);  
   
  m_sSubject   =   CString(m_pMessage->lpszSubject);  
   
  m_sMessage   =   CString(m_pMessage->lpszNoteText);  
   
  if   (m_pMessage->flFlags   &   MAPI_UNREAD)  
  m_bRead   =   true;  
  else  
  m_bRead   =   false;  
   
  //   Deallocate   the   memory   for   the   message  
   
  lpfnMAPIFreeBuffer(m_pMessage);  
   
  return   true;  
  }  
   
   
  //   ******************  
  //   *                                 *  
  //   *     FirstMessage     *  
  //   *                                 *  
  //   ******************  
  //   Description: Moves   to   the   first   message   in   the   inbox  
   
  BOOL   CRobotMail::FirstMessage(BOOL   bMarkAsRead)  
  {  
  if   (!m_bInitialized)   return   false;  
   
  m_bNewOnly   =   false;  
   
  //   Find   the   first   message  
   
  ULONG   lResult   =   lpfnMAPIFindNext(m_lhSession,  
    NULL,  
    NULL,  
    NULL,  
    MAPI_LONG_MSGID,  
    0,  
    m_pMessageID);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
   
  //   Read   the   message   (that   was   found   by   MAPIFindNext)  
   
  long   nFlags   =   MAPI_SUPPRESS_ATTACH;  
  if   (!bMarkAsRead)  
  nFlags   =   nFlags     and     MAPI_PEEK;  
  lResult   =   lpfnMAPIReadMail(m_lhSession,  
        NULL,  
        m_pMessageID,  
        nFlags,  
        0,  
        &m_pMessage);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
   
  m_sFrom   =   CString(m_pMessage->lpOriginator->lpszName);  
   
  m_sFromAddress   =   CString(m_pMessage->lpOriginator->lpszAddress);  
   
  m_sDate   =   CString(m_pMessage->lpszDateReceived);  
   
  m_sSubject   =   CString(m_pMessage->lpszSubject);  
   
  m_sMessage   =   CString(m_pMessage->lpszNoteText);  
   
  if   (m_pMessage->flFlags   &   MAPI_UNREAD)  
  m_bRead   =   true;  
  else  
  m_bRead   =   false;  
   
  //   Deallocate   the   memory   for   the   message  
   
  lpfnMAPIFreeBuffer(m_pMessage);  
   
  return   true;  
  }  
   
   
  //   *****************  
  //   *                               *  
  //   *     NextMessage     *  
  //   *                               *  
  //   *****************  
  //   Description: Returns   a   count   of   the   number    
  //                             of   messages   (both   read   and   unread)  
   
  BOOL   CRobotMail::NextMessage(BOOL   bMarkAsRead)  
  {  
  if   (!m_bInitialized)   false;  
   
  if   (!m_bInitialized)   return   false;  
   
  //   Find   the   next   message  
   
  long   nFlags   =   MAPI_LONG_MSGID;  
  if   (m_bNewOnly)  
  nFlags   =   nFlags     and     MAPI_UNREAD_ONLY;  
   
  ULONG   lResult   =   lpfnMAPIFindNext(m_lhSession,  
    NULL,  
    NULL,  
    m_pMessageID,  
    nFlags,  
    0,  
    m_pMessageID);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
   
  //   Read   the   message   (that   was   found   by   MAPIFindNext)  
   
  nFlags   =   MAPI_SUPPRESS_ATTACH;  
  if   (!bMarkAsRead)  
  nFlags   =   nFlags     and     MAPI_PEEK;  
  lResult   =   lpfnMAPIReadMail(m_lhSession,  
        NULL,  
        m_pMessageID,  
        nFlags,  
        0,  
        &m_pMessage);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
   
  m_sFrom   =   CString(m_pMessage->lpOriginator->lpszName);  
   
  m_sFromAddress   =   CString(m_pMessage->lpOriginator->lpszAddress);  
   
  m_sDate   =   CString(m_pMessage->lpszDateReceived);  
   
  m_sSubject   =   CString(m_pMessage->lpszSubject);  
   
  m_sMessage   =   CString(m_pMessage->lpszNoteText);  
   
  if   (m_pMessage->flFlags   &   MAPI_UNREAD)  
  m_bRead   =   true;  
  else  
  m_bRead   =   false;  
   
  //   Deallocate   the   memory   for   the   message  
   
  lpfnMAPIFreeBuffer(m_pMessage);  
   
  return   true;  
  }  
   
   
  //   *****************  
  //   *                               *  
  //   *     SendMessage     *  
  //   *                               *  
  //   *****************  
  //   Description: Sends   a   message  
   
  BOOL   CRobotMail::SendMessage(CString   sTo,  
    CString   sSubject,  
    CString   sMessage,  
    CString   sAttachment)  
  {  
  if   (!m_bInitialized)   return   false;  
   
  char   recipient[512];  
  char   subject[512];  
  char   path[512];  
  char   filename[512];  
  char   text[5000];  
  CString   sPath,   sFilename;  
  MapiFileDesc   m_FileInfo;  
   
  memset(&m_message,   0,   sizeof(m_message));  
  m_message.ulReserved   =   0;  
  m_message.lpszMessageType   =   NULL;  
  strcpy(subject,   sSubject);  
  m_message.lpszSubject   =   subject;  
  strcpy(text,   sMessage);  
  m_message.lpszNoteText   =   text;  
  m_message.flFlags   =   MAPI_SENT;  
  m_message.lpOriginator   =   NULL;  
  m_message.nRecipCount   =   1;  
  strcpy(recipient,   sTo);  
  ULONG   lResult   =   lpfnMAPIResolveName(m_lhSession,  
  0,  
  recipient,  
  0,  
  0,  
  &m_message.lpRecips);  
  if   (lResult   !=   SUCCESS_SUCCESS)  
  return   false;  
  if   (sAttachment   ==   "")  
  m_message.nFileCount   =   0;  
  else  
  {  
  int   nPos   =   sAttachment.ReverseFind('\\');  
  if   (nPos   ==   -1)  
  {  
  sPath   =   sAttachment;  
  sFilename   =   sAttachment;  
  }   //   End   if  
  else  
  {  
  sPath   =   sAttachment;  
  sFilename   =   sAttachment.Mid(nPos   +   1);  
  }   //   End   else  
   
  strcpy(path,   sPath);  
  strcpy(filename,   sFilename);  
   
  m_message.nFileCount   =   1;  
  m_FileInfo.ulReserved   =   0;  
  m_FileInfo.flFlags   =   0;  
  m_FileInfo.nPosition   =   sMessage.GetLength()   -   1;  
  m_FileInfo.lpszPathName   =   path;  
  m_FileInfo.lpszFileName   =   filename;  
  m_FileInfo.lpFileType   =   NULL;  
  m_message.lpFiles   =   &m_FileInfo;  
  }   //   End   else  
   
  lResult   =   lpfnMAPISendMail(0,   0,   &m_message,   0,   0);  
   
  lpfnMAPIFreeBuffer(m_message.lpRecips);  
   
  if   (lResult   ==   SUCCESS_SUCCESS)  
  return   true;  
  else  
  return   false;  
  }  
   
   
  //   ****************  
  //   *     Destructor     *  
  //   ****************  
   
  CRobotMail::~CRobotMail()  
  {  
  if   (!m_bInitialized)   return;  
  m_bInitialized   =   false;  
  }  
  Top

相关问题

  • 发邮件代码
  • 求自动发送邮件的代码!
  • 发邮件代码那里错了??
  • 求用c语言发邮件代码
  • 谁有Web方式收发邮件的PHP代码?
  • 谁帮我写一段发邮件的的代码?谢了
  • 那位有SMTP发邮件的源代码或是资料呀!
  • 不能发送邮件(内付源代码),请帮忙查错?
  • 谁能给我一段发送邮件的代码?定加分
  • 那位老兄有java(jsp、servlet)发邮件的源代码?

关键词

  • visual c++
  • crobotmail
  • pmessage
  • pmessageid
  • mapi
  • lhsession
  • binitialized
  • lpfnmapifindnext
  • bmarkasread
  • hinstmail

得分解答快速导航

  • 帖主:haidong
  • zjy
  • jamesw

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo