如题 主要代码如下:
int                  nIndex = 0;
int                  nRecipients = 0;
MapiRecipDesc*       pRecipients = NULL;
int                  nAttachments = 0;
MapiFileDesc*        pAttachments = NULL;
ULONG                status = 0;
MapiMessage          message={0}; MapiRecipDesc* pSetFrom = NULL;
pRecipients = new MapiRecipDesc; pSetFrom = new MapiRecipDesc; pAttachments = new MapiFileDesc; if (pRecipients||pSetFrom)
{
// set from
pSetFrom->ulReserved                 = 0;
pSetFrom->ulRecipClass               = MAPI_ORIG;
pSetFrom->lpszAddress                = "[email protected]";
pSetFrom->lpszName                   = "[email protected]";//(LPTSTR)(LPCTSTR)m_from.begin()->second;
pSetFrom->ulEIDSize                  = 0;
pSetFrom->lpEntryID                  = NULL; pRecipients->ulReserved                 = 0;
pRecipients->ulRecipClass               = MAPI_TO;
pRecipients->lpszAddress                = "[email protected]";
pRecipients->lpszName                   = "[email protected]";//(LPTSTR)(LPCTSTR)m_to.begin()->second;
pRecipients->ulEIDSize                  = 0;
pRecipients->lpEntryID                  = NULL;
}
if (pAttachments)
{
// add attachments
pAttachments->ulReserved        = 0;
pAttachments->flFlags           = 0;
pAttachments->nPosition         = -1;//0xFFFFFFFF;
pAttachments->lpszPathName      = "C:\\ceshi.txt";
pAttachments->lpszFileName      = "ceshi.txt";
pAttachments->lpFileType        = 0;
} message.ulReserved                        = 0;
message.lpszSubject                       = "ceshi";
message.lpszNoteText                      = "fflskdjflsjflsd";
message.lpszMessageType                   = NULL;
message.lpszDateReceived                  = NULL;
message.lpszConversationID                = NULL;
message.flFlags                           = 0;
message.lpOriginator                      = pSetFrom;
message.nRecipCount                       = 1; // don't count originator
message.lpRecips                          = pRecipients;
message.nFileCount                        = 1;
message.lpFiles                           = pAttachments; status = m_lpMapiSendMail(0, 0, &message,  MAPI_DIALOG , 0); if (pRecipients)
delete  pRecipients; if (nAttachments)
delete  pAttachments; if (pSetFrom)
{
delete pSetFrom;
}

解决方案 »

  1.   

    pSetFrom->lpszAddress                = "[email protected]"; 
    改成下面的语句试试:
    pSetFrom->lpszAddress                = "smtp:[email protected]"; 
      

  2.   

    如果还没解决问题,可能需要设置ENTRYID了。在MAPI里面,每个对象都有一个唯一的永久的ENTRYID,如果收件人不在地址簿中,可能需要首先把它添加到地址簿以便获得一个ENTRYID。
      

  3.   

    The format of an address pointed to by the lpszAddress member is [address type][e-mail address]. 看看你的adress Type是不是SMTP了
      

  4.   


    这个用哪个API设置啊?可以给点提示吗????
      

  5.   

    是smtp的没错  还了好几个邮箱都不行,直接在outlook上的发件人上填上这个邮箱地址发送就成功了。
      

  6.   

    搞ENTRYID就有点复杂了,没有几十行代码是搞不定的。先去看看操作地址簿的API帮助吧。
      

  7.   

    没有简单点的方法了吗?  其实就是自定义发送人,如果把message.lpOriginator = pSetFrom;改为 message.lpOriginator = NULL;的话就直接以outlook设置的默认帐户发送了,如果outlook中没有设置默认帐户的话,弹出的outlook没有发送按钮了这是什么问题。
      

  8.   

    这就是你的错了。
    MAPI必须首先定义好自己的账号(发送者),账号有各种属性,比如SMTP服务器、账号名、密码等等,MAPI需要这些信息跟SMTP服务器通信。你直接搞个其它的发送人,系统怎么通信去?