How to place the new mail in outbox of outlook programatically
-
I need to place the mail in outbox i tried with automation and also with mapi apis,but no success anone have idea regarding this one Thanx
-
I need to place the mail in outbox i tried with automation and also with mapi apis,but no success anone have idea regarding this one Thanx
Show us the relevant code that is not working, and maybe we can offer suggestions.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
Show us the relevant code that is not working, and maybe we can offer suggestions.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
hello david this is my code for saving mail in outbox this is automation code its notworking but when i make call to send it send mail directly but i only need to place in outbox folder _Application pApp; COleException e; if(!pApp.CreateDispatch("Outlook.Application", &e)) { CString str; str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc); AfxMessageBox(str, MB_SETFOREGROUND); return; } COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); _NameSpace pNameSpace; MAPIFolder pOutbox; _Items pOutboxItems; Attachments pAttachments; Recipients pRecipients; Recipient pRecipient; // Create NameSpace pointer. pNameSpace = pApp.GetNamespace("MAPI"); pNameSpace.Logon(covOptional, covOptional, covOptional, covOptional); // Prepare a new mail message _MailItem pNewMail(pApp.CreateItem(0)); pOutbox = pNameSpace.GetDefaultFolder(4);//getoutbox folder pOutboxItems = pOutbox.GetItems(); pNewMail=pOutboxItems.Add(covOptional);//put the message in out boxx pNewMail.SetTo("global_com2000@yahoo.com"); pNewMail.SetSubject("Test..."); pNewMail.SetBody("Hi Mapi\n\n"); pRecipients.Add("global_com2000@yahoo.com"); // Resolve the recipient address. pRecipients .ResolveAll(); pNameSpace.Logoff();
-
hello david this is my code for saving mail in outbox this is automation code its notworking but when i make call to send it send mail directly but i only need to place in outbox folder _Application pApp; COleException e; if(!pApp.CreateDispatch("Outlook.Application", &e)) { CString str; str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc); AfxMessageBox(str, MB_SETFOREGROUND); return; } COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); _NameSpace pNameSpace; MAPIFolder pOutbox; _Items pOutboxItems; Attachments pAttachments; Recipients pRecipients; Recipient pRecipient; // Create NameSpace pointer. pNameSpace = pApp.GetNamespace("MAPI"); pNameSpace.Logon(covOptional, covOptional, covOptional, covOptional); // Prepare a new mail message _MailItem pNewMail(pApp.CreateItem(0)); pOutbox = pNameSpace.GetDefaultFolder(4);//getoutbox folder pOutboxItems = pOutbox.GetItems(); pNewMail=pOutboxItems.Add(covOptional);//put the message in out boxx pNewMail.SetTo("global_com2000@yahoo.com"); pNewMail.SetSubject("Test..."); pNewMail.SetBody("Hi Mapi\n\n"); pRecipients.Add("global_com2000@yahoo.com"); // Resolve the recipient address. pRecipients .ResolveAll(); pNameSpace.Logoff();
Try this:
_Application app;
_NameSpace ns;
MAPIFolder folderOutbox;
_Items itemsMessages;
_MailItem mi;
long olFolderOutbox((long) 4);
COleVariant vtOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR),
vtTrue((short) TRUE);if (app.CreateDispatch("Outlook.Application") == TRUE)
{
ns = app.GetNamespace("MAPI");ns.Logon(vtOptional, vtOptional, vtTrue, vtTrue); folderOutbox = ns.GetDefaultFolder(olFolderOutbox); itemsMessages = folderOutbox.GetItems(); mi = itemsMessages.Add(vtOptional); mi.SetTo("global\_com2000@yahoo.com"); mi.SetSubject("Test..."); mi.SetBody("Hi Mapi\\n\\n"); mi.Send(); ns.Logoff();
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)