|
I have an earlier version of this code I think, but I was getting an arithmetic overflow recently. It happened just after I converted to Windows 8.1 but then I also got more memory so maybe it was that.
In the code it converts an IntPtr to an int to do arithmetic but this was failing with an overflow.
I have altered my code so that it just keeps it as an IntPtr, there is no need to convert to an int. You can still add values to it.
e.g. replacement code in AllocRecips:
IntPtr runptr = ptrr;
for( int i = 0; i < recpts.Count; i++ )
{
Marshal.StructureToPtr( recpts[i] as MapiRecipDesc, runptr, false );
runptr += rsize;
}
|
|
|
|
|
I want to develop a asp.net application using C#.net2008.I want to write a PST file without using Microsoft.Office.Interop.Outlook rather. Is it possible then how to go about since I donot know much about MAPI or C++. The user would select task,calender etc from my application and would export in a PST format which they can import into their local Microsoft Outlook. Thanks in advance.I need it urgently and would wait for your positive response.
|
|
|
|
|
|
Hi, in this example i can see the messages of "inbox" folder, but ... How I can see messages of "send items"?
Thanks you and sorry for my bad english.
|
|
|
|
|
|
After closing the project for the 10th time, I figured out:
Windows 7: x64
Office: x86
This project compiled to x64, so couldn't use the x86 Messaging Subsystem. I changed the 'Platform target" from "Any CPU" to x86: and it works perfectly!!!!
So, if you encounter this unspecified error, consider the match between the project and Office/Outlook.
Chau chau,
Pascalos
|
|
|
|
|
Hi,
Can someone explain why the MAPIlogin works in a GUI application, but when you move the code to a console application MAPILogon will always return errorcode 3?
Thanks,
Bart
|
|
|
|
|
It's very usuful for me. Thank you very much.
|
|
|
|
|
I find that I get some stupid behaviour on my machine if I call the Login method: Outlook begins running the wizard to set up a new mail account.
But I can avoid this by just doing:
int error = MAPISendMail(IntPtr.Zero, hWnd, message, 0x00000008 | 0x00000001, 0);
So no session creation at all, just calling that one API works better. The flags I'm using are:
MAPI_LOGON_UI = 0x00000001
MAPI_DIALOG = 0x00000008
This is so the user can review the email before sending, and this also gets rid of the security warning timer.
|
|
|
|
|
|
Hi,
I had a requirement to send mail using the default mail client installed ,If no mail client can be found then to try using smtp relay.I had used mapi with delphi ,in that case the security warning comes up , but there is no flickering on the screen,however with c# mapi implementation I get a flickering all the time whenever we click allow on the security warning..Is there way to address it right now I am making use of sendtoback..and how do i decrease the time taken for the activation of the allow button .Is it possible?
Thanks..
|
|
|
|
|
If you want to send mail with attachments and avoid the security wait then I would recommend using an amazing c# wrapper that uses extended MAPI. This gets around all security warnings so your system can be automated. You said you used MAPI before but I beleive that was just simple MAPI. The extended version bypasses it.
http://www.codeproject.com/internet/CMapiEx.as[^]
It is a great wrapper and will solve this problem.
|
|
|
|
|
Thanks for the sample. I've been digging around trying to find tutorials on MAPI with C# and found either unmanaged code that wouldn't work with my solution or inbox readers. None of them explained the simple function of sending a message.
I know this is old, but thanks for posting. After six years, it's still useful.
|
|
|
|
|
Hi All
This is really appriciated coding.but myy problem is that i want to read all mails directly from exchange server inbox.Please help me.It's very urgent for me.
ushagupta
|
|
|
|
|
Hello, could you please help me. I can't find somewhere about my issue. Is it possible to get message priority using Simple MAPI?
Or maybe do you know other way about how to get all messages + attachments from Exchange mailbox?
Thanks
Regards
Andrej
modified on Wednesday, January 02, 2008 9:24:12 AM
|
|
|
|
|
Pls let me knnow i do i read mails that is catagorize in seperate folder out of indox.
|
|
|
|
|
Hi,
Can any body help me to send the HTML page as a body,
in this application.
TIA
Amar
|
|
|
|
|
Great library.
I am having problems with certain messages putting in the recipient's email address as the email type when I send a message in Outlook 2003 SP3 using this library. I went into the Mapi.cs send method and attempted to set this property to "SMTP" in the code using the code below:
//PL 10/16/2007 - set the message type
lastMsg.messageType = "SMTP";
This caused Outlook to throw up a message box saying method not found.
Any ideas on how I can set the messageType property programmatically using the SimpleMapi.NET library?
Thanks,
P
|
|
|
|
|
I found out how to fix this. I had to append the messageType to the recipient address string like so:
recipientAddress = "SMTP:foo@bar.com"
This fixes the problem. I found this out by digging around on msdn and looking at the MAPI API documentation. The link to the recipients section where I found this is below.
http://msdn2.microsoft.com/en-us/library/ms529097.aspx
Hopefully this will help someone somewhere some day. hahaha
|
|
|
|
|
It does, thx!
|
|
|
|
|
Hello!
I'm using this lib for sending mails and find it great, to use the user prefered mailer.
But when i try to get the mails from thunderbird client over SimpleMapi.NET, i get only the last from thunderbird received email. By trying to get the next mail ( Mapi.Net(...) ), i get an error code (last mail).
Is it possible, that some of the parameters has changed in the API?
|
|
|
|
|
it's working strange with thunderbird, anyone knows how I can get into thunderbirds folders/mails/attachments etc. thru C# ?
|
|
|
|
|
Simple MAPI.NET doesn't works with Notes. It places recipient name + text + recipient name second time in my "To" field. Are there any ideas how to fix it?
|
|
|
|
|
This is a bug with the Notes client. It is fixed in the latest 6.5.6 FP1 release.
Cheers,
Aaron
|
|
|
|
|
Hi.I write the code followed and want to put message to inbox. i have installed Outlook in my computer which is configured to exchenge server in the other machine. I want to see my message in Exchange server before send receive in my local Outlook in my case it is not like that message i get the message but only after manual send receive. Please help me to understand what is wrong i am new in MAPI. Thank you.
#include "MailGen.h"
enum { _ENTRYID, _DISPLAY_NAME, _FINDER_ENTRYID, _SUBFOLDERS };
MailGen::MailGen(void)
{
MAPIInitialize(0);
}
MailGen::~MailGen(void)
{
MAPIUninitialize();
}
BOOL MailGen::AddMailToInbox(CString strProfileName)
{
LPMAPISESSION pSession;
LPMAPIFOLDER lpProcessedFolder;
ULONG cbDefStoreEid = 0;
LPENTRYID pDefStoreEid = NULL;
ULONG ulValues;
LPSPropValue pPropValues = NULL;
CString csSearchedMBox;
LPMDB pDefMsgStore = NULL;
LPSPropValue lpRowProp = NULL;
LPSPropValue pVal = NULL;
LPMESSAGE m_pMessage;
try
{
CHECKERR(MAPILogonEx(0, // Handle to parent window
(LPTSTR)(LPCTSTR)strProfileName, // Profile name
NULL, // Password
MAPI_EXTENDED | MAPI_USE_DEFAULT | MAPI_NEW_SESSION,
// MAPI_PASSWORD_UI, // Logon flags
&pSession),"Obtain MAPI session - MAPILogonEx");
LPMAPITABLE lptMsgStores = NULL;
// Obtain a table of message stores from the session.
CHECKERR( pSession->GetMsgStoresTable(NULL, &lptMsgStores), "Obtain a table of message stores from the session - lpSession->GetMsgStoresTable" );
// Look for the default store. If you are not online,
// this is located in the Offline folder.
SizedSPropTagArray(2, tagStores) =
{
2, PR_DEFAULT_STORE, PR_ENTRYID
};
LPSRowSet pRowSetStores = 0;
SRestriction sRes;
SPropValue propStore;
propStore.ulPropTag = PR_DEFAULT_STORE;
propStore.Value.b = TRUE;
propStore.dwAlignPad = 0;
sRes.rt = RES_PROPERTY;
sRes.res.resProperty.relop = RELOP_EQ;
sRes.res.resProperty.ulPropTag = PR_DEFAULT_STORE;
sRes.res.resProperty.lpProp = &propStore;
CHECKERR( HrQueryAllRows(lptMsgStores,
(LPSPropTagArray)&tagStores,
&sRes,
0,
0,
&pRowSetStores),
"Get default message store - HrQueryAllRows");
if (pRowSetStores->cRows > 0)
{
LPSPropValue pPropStore = pRowSetStores->aRow[0].lpProps;
LPMDB pMDBDefault = 0;
//lpRowProp = pPropStore->aRow[0].lpProps;
CHECKERR( pSession->OpenMsgStore(0,
pPropStore[1].Value.bin.cb,
(LPENTRYID)pPropStore[1].Value.bin.lpb,
0,
MDB_NO_DIALOG| MAPI_BEST_ACCESS | MAPI_DEFERRED_ERRORS,
&pDefMsgStore), "Open the message store - pSession->OpenMsgStore");
CHECKERR( pDefMsgStore->GetProps(NULL,
0,
&ulValues,
&pPropValues), "pDefMsgStore->GetProps");
CHECKERR( HrGetOneProp( pDefMsgStore, PR_IPM_SUBTREE_ENTRYID, &pVal ), "HrGetOneProp - PR_IPM_SUBTREE_ENTRYID" );
//ULONG ulObjType = 0;
//CHECKERR( pDefMsgStore->OpenEntry( pVal->Value.bin.cb,
// (LPENTRYID)pVal->Value.bin.lpb,
// NULL, //We want the default interface (IMAPIFolder)
// MAPI_BEST_ACCESS, //Flags
// &ulObjType, //Object returned type
// (LPUNKNOWN *) &lpProcessedFolder), "lpMDB->OpenEntry"); //Returned folder
lpProcessedFolder = OpenInbox(pDefMsgStore);
//CHECKERR(lpProcessedFolder->CreateMessage(NULL,0,&m_pMessage),"inbox->CreateMessage()");
m_pMessage = CreateMessag(lpProcessedFolder,"FROMNAME","fromname@yahoo.com","Test Subject","Test Body");
SPropValue prop;
prop.ulPropTag=PR_MESSAGE_FLAGS;
prop.Value.l=MSGFLAG_UNSENT | MSGFLAG_FROMME;
CHECKERR(m_pMessage->SetProps(1,&prop,NULL),"m_pMessage->SetProps()");
m_pMessage->SaveChanges(FORCE_SAVE);
pSession->Logoff(NULL,0,0);
/*csSearchedMBox = "Mailbox - ";
csSearchedMBox += pPropValues[1].Value.lpszA;*/
}
}
catch( std::string& str )
{
MessageBox(NULL,str.c_str(),NULL, MB_OK | MB_ICONSTOP);
return false;
}
if (pPropValues)
MAPIFreeBuffer(pPropValues);
if (pDefMsgStore)
{
ULONG uflags = LOGOFF_NO_WAIT;
pDefMsgStore->StoreLogoff(&uflags);
pDefMsgStore->Release();
}
if (lpProcessedFolder)
{
lpProcessedFolder->Release();
}
if (pDefStoreEid)
MAPIFreeBuffer(pDefStoreEid);
if (pSession)
{
pSession->Logoff(0, MAPI_LOGOFF_SHARED, 0);
pSession->Release();
}
return true;
}
LPMESSAGE MailGen::CreateMessag(LPMAPIFOLDER folder,CString fromName,CString fromEMail,CString subject,CString body)
{
LPMESSAGE m_pMessage;
CHECKERR(folder->CreateMessage(NULL,0,&m_pMessage),"inbox->CreateMessage()");
set_SenderName(m_pMessage,fromName);
set_SenderEmail(m_pMessage,fromEMail);
set_Subject(m_pMessage,subject);
set_Body(m_pMessage,body);
return m_pMessage;
}
void MailGen::CHECKERR( HRESULT hr, const char* msg )
{
if( hr != S_OK ){
char buf[11];
itoa( hr, buf, 16 );
std::string err("FAILED with error - ");
err += buf;
err += ", ";
err += msg ? msg : "";
throw err;
}
}
LPMAPIFOLDER MailGen::OpenInbox(LPMDB m_pMsgStore)
{
if(!m_pMsgStore) return NULL;
ULONG cbEntryID;
LPENTRYID pEntryID;
DWORD dwObjType;
LPMAPIFOLDER pFolder;
CHECKERR(m_pMsgStore->GetReceiveFolder(NULL,0,&cbEntryID,&pEntryID,NULL),"m_pMsgStore->GetReceiveFolder()");
m_pMsgStore->OpenEntry(cbEntryID,pEntryID, NULL, MAPI_BEST_ACCESS ,&dwObjType,(LPUNKNOWN*)&pFolder);
MAPIFreeBuffer(pEntryID);
return pFolder;
}
void MailGen::set_Subject(LPMESSAGE m_pMapiMessage,LPCTSTR subject)
{
CString strSubject = subject;
if(strSubject.GetLength()>0 && m_pMapiMessage) {
SPropValue prop;
prop.ulPropTag=PR_SUBJECT;
prop.Value.LPSZ=(TCHAR*)subject;
m_pMapiMessage->SetProps(1,&prop,NULL);
}
}
void MailGen::set_SenderName(LPMESSAGE m_pMapiMessage,LPCTSTR senderName)
{
CString strSenderName=senderName;
if(strSenderName.GetLength() > 0 && m_pMapiMessage) {
SPropValue prop;
prop.ulPropTag=PR_SENDER_NAME;
prop.Value.LPSZ=(TCHAR*)senderName;
m_pMapiMessage->SetProps(1,&prop,NULL);
}
}
void MailGen::set_SenderEmail(LPMESSAGE m_pMapiMessage,LPCTSTR senderEmail)
{
CString strSenderEmail=senderEmail;
if(strSenderEmail.GetLength()>0 && m_pMapiMessage) {
SPropValue prop;
prop.ulPropTag=PR_SENDER_EMAIL_ADDRESS;
prop.Value.LPSZ=(TCHAR*)senderEmail;
m_pMapiMessage->SetProps(1,&prop,NULL);
}
}
void MailGen::set_Body(LPMESSAGE m_pMapiMessage,LPCTSTR body)
{
CString strBody=body;
if(strBody.GetLength()>0 && body) {
LPSTREAM pStream=NULL;
if(m_pMapiMessage->OpenProperty(PR_BODY, &IID_IStream, 0, MAPI_MODIFY | MAPI_CREATE, (LPUNKNOWN*)&pStream)==S_OK) {
pStream->Write(body,(ULONG)(_tcslen(body)+1)*sizeof(TCHAR),NULL);
pStream->Release();
pStream = NULL;
}
}
}
|
|
|
|
|