|
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;
}
}
}
|
|
|
|
|
Hi,
I would like to show an automatically generated Email to the user before sending it.
So I set the MAPISendMail(...) Flag to MapiDialog (0x8).
This works fine for Thunderbird as default Mail client.
Outlook Express complains: "Mindestens ein Teil dieser Nachricht konnte nicht angezeigt werden."
this should be in english: "At least on part of the message could not be shown."
Setting the flag to 0, the Mail is sent without problems..... but I need the dialog to be shown.
Any ideas how to fix this?
thanks a lot
Dan
|
|
|
|
|
Hy,
here is my code example:
Where is here my error?
if (mapi.Logon(IntPtr.Zero) == false)
{
......
}
string mailAdress = "SMTP:a@b.de";
mapi.AddRecip(mailAdress, null, false);
if (mapi.Send(subject,message))
{
Console.WriteLine("Erfolgreich gesendet");
}
else
{
Console.WriteLine("Error: {0}", mapi.Error());
}
|
|
|
|
|
I can open a new message with an attachment in Outlook 2003 and Thunderbird, but not in Outlook 2007, where it opens a new mail message with no attachments. Any ideas how to get it to work in Outlook 2007? I know it's possible since Adobe Acrobat Reader can still attach files in emails with one click.
I am using this simple code from the article:
Win32Mapi.Mapi ma = new Win32Mapi.Mapi();
ma.Logon(IntPtr.Zero);
ma.Attach(@"c:\temp.txt");
ma.Send("Subjectheading", "Bodytext", false);
ma.Logoff();
|
|
|
|
|
I'm using part of this class to send an automatically generated mail message. I want the application to pop up the mail form (MAPIDialog). This works great as long as I use it from the primary form. However, when I use it from a secondary form (that is click a button on the primary form to pop up a second form and then click another button to send the mail), I get my mail form to pop up but the mail form has an hourglass cursor and it appears to be hung.
Any ideas why this might happen?
Thanks.
|
|
|
|
|
I also had this problem and the only workaround i found was to hide the form prior to calling MAPI.
ie,
try
{
// workaround a MAPI bug:
// hide the window, otherwise MAPI calls below hang with a wait cursor (hourglass)
Visible = false;
// ... call MAPI ...
}
finally
{
Visible = true; // restore visibility
}
|
|
|
|
|
Just what i was looking for, with a little extra as well.
Thanks very much.
ben
|
|
|
|
|
Thanks for this article. Well written and provides a very useful class. I am using it in one of my projects, with your name intact on the class documentation . I did document the rest of your code though ..... lol
|
|
|
|
|
Anybody know how this approach for accessing Outlook emails compares with the following:
http://www.codeproject.com/useritems/extract_oulook_2003_NET.asp?forumid=280510&select=1439980&df=100&msg=1439980#xx1439978xx
Not sure if they are equivlent in functionalities or not. I also posted a similar question in the comment section of that article.
Thanks a lot!
|
|
|
|
|
I am using MS Outlook and XP. Send mail works fine (the user gets a dialog). But if the user cancels the dialog, from close button or otherwise, and Outlook is running, Outlook hangs with send/receive error message. Needs to restart Outlook
kperwaiz
|
|
|
|
|
Change the send code to the following. If you do not log off and let the object go out of scope you have the issue you are talking about.
try
{
ma.AddRecip(to, null, false);
if (!ma.Send(subject, body))
{
MessageBox.Show("MAPISendMail failed! : " + ma.Error());
return;
}
MessageBox.Show("SimpleMAPICon: email sent successfully.");
}
finally
{
ma.Logoff();
}
|
|
|
|
|
To start off, great code! It works very well. In my application I'm using the Outlook COM object and am able to send emails as well. But I get the infamous Outlook security popup foreach email that is sent out. The message states "A program is trying to automatically send e-mail on your behalf. Do you want to allow this?" Then you have to manually select "Yes" or "No". The above code trigers this popup as well and I was wondering if anyone figured out how to avoid this popup.
Thanks.
David
www.dpatterson.net
|
|
|
|
|
This Microsoft article may help, see Scenario 2:
http://support.microsoft.com/kb/290499/EN-US/[^]
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
David, it seems that u have solved the solution out of the link http://support.microsoft.com/kb/290499/EN-US/[^] refered by Ant.
Can u plz brief it here?
|
|
|
|
|
Requiring an Exchange server isn't acceptable in every situation. I've been looking around for this all day. According to
this, you can write a COM object inside Outlook.
I opt to just use the free tool ClickYes. Although this brings back the security problem that brought the crazy dialog, it fixes the problem in our simple systems. Use it at your own risk...
|
|
|
|
|
Hi,
Thanx for the Great article.
It seems that there are security issues with the app.
when I start the app, I get a messagae from Microsoft Outlook..
Saying that "A program is trying to access the email addresses you have stored in the outlook. Do you want to allow this ?"...
How do we stop this message from coming ???
And what are the security isssues if any ???
Any help will be great.
Regards,
Saleem
|
|
|
|
|
This is a great article and put me on the path to my solution, which was implementing a "send to" in my vb.net app.
It's missing one very easy MAPI function which is perfect for this purpose. So if that's what you're browsing for:
<DllImport("MAPI32.DLL")> _
Public Shared Function MAPISendDocuments(ByVal ulUIParam As IntPtr, ByVal lpszDelimChar As String, _
ByVal lpszFullPaths As String, ByVal lpszFileNames As String, ByVal rsv As Integer) As Integer
End Function
Private Class Mailer
Public filename As String
Public Sub Start()
MAPISendDocuments(IntPtr.Zero, ";", Me.filename, "", 0)
End Sub
End Class
Public Sub SendEmail()
'Mail the file on a new thread so the mail dialog won't be modal to our application
Dim m As New Mailer
m.filename = "C:\yourfile.txt"
Dim t As Threading.Thread
t = New Threading.Thread(AddressOf m.Start)
t.Start()
End Sub
The first argument to the API function is your window handle, and a zero is supposed to cause the dialog to be modeless. There is a similar scheme for the MAPISendMail() function. For me it was always modal, regarless of the value of this argument, so I just started a new thread. If you want a modal mail window, ignore the threading stuff and call the function directly.
|
|
|
|
|
Is it possible to set ContentType to HTML?
|
|
|
|
|
The sample is fantastic but when I try to send an email without Outlook being open, I get the error message:
"Failed to send email: MAPI login failure [3]".
Is the the expected behaviour? Can I get it to send without a client being open?
Maybe I need to check if a client is open first, then advise the user to start their client before sending?
TIA
|
|
|
|
|