|
How can I add attachment to the message - I dont see any function that does that?
|
|
|
|
|
Answered myself:
In CreateMessage() add the following *before*
rangeva wrote:
if (bHighImportance)
{
prop.ulPropTag = PR_IMPORTANCE;
prop.Value.l = IMPORTANCE_HIGH;
hr = m_pMessage->SetProps(1, &prop, NULL);
if (FAILED(hr)) return false;
}
return true;
rangeva wrote:
/************ Attachment ***************************/
ULONG ulAttNum;
CComPtr<iattach> pAtt;
hr = m_pMessage->CreateAttach(
NULL, // standard interface
0, // don't defer errors
&ulAttNum, // put the index of the attachment here (probably 0?)
&pAtt); // put the attachment here.
if (FAILED(hr)) return false;
{
CComPtr<istream> strAttachment;
hr = pAtt->OpenProperty(
PR_ATTACH_DATA_BIN, // the binary data of the attachment
(LPIID)&IID_IStream, // open it as a stream
0, // no extra data for the stream
MAPI_MODIFY | MAPI_CREATE, // want to write to it, create it because it's not there yet
(LPUNKNOWN*) &strAttachment); // put it in here.
if (FAILED(hr)) return false;
const unsigned char * lpbSampleRTFBytes = (const unsigned char*)apBuffer;
ULONG cSampleRTFLength = anBufSize;
ULONG cBytesWritten;
hr = strAttachment->Write(
lpbSampleRTFBytes, // this is the data
cSampleRTFLength, // this much data
&cBytesWritten); // reuse this variable -- how much data we got back
if (FAILED(hr)) return false;
}
// Fill in the rest of the attachment data:
enum {FILENAME,METHOD,RENDERING,NUM_ATT_PROPS};
SPropValue spvAttach[NUM_ATT_PROPS];
// Some filename or other.
spvAttach[FILENAME].ulPropTag = PR_ATTACH_FILENAME;
spvAttach[FILENAME].Value.lpszA = "FileName.ext";
// How do we attach it? The `value of the' attachment is in the PR_ATTACH_DATA_BIN property.
spvAttach[METHOD].ulPropTag = PR_ATTACH_METHOD;
spvAttach[METHOD].Value.l = ATTACH_BY_VALUE;
// Don't render it as anything, just attach it.
spvAttach[RENDERING].ulPropTag = PR_RENDERING_POSITION;
spvAttach[RENDERING].Value.l = -1;
hr = pAtt->SetProps(
NUM_ATT_PROPS, // how many to set?
(LPSPropValue)&spvAttach, // what do we want to set?
NULL); // no problem array back.
if (FAILED(hr)) return false;
// And save these changes. We're done with this attachment, so don't keep it open
// for reading/writing/suchlike.
hr = pAtt->SaveChanges(0);
if (FAILED(hr)) return false;
/***************************************************/
|
|
|
|
|
I do not think your extra code compile.
What is apBuffer?
What is anBufSize?
How can I make this work with a file I have created and want to attach?
Thank you/
|
|
|
|
|
apBuffer = The attachment binary data and anBufSize is its size
|
|
|
|
|
Thank you. I can add data to my file but can you say how to copy my binary file to the attachment so that if I have a file file.bin that I must attach, I must read the data from that file and write it to the my attachment using the IStream I got when I called OpenProperty() on my attachment.
|
|
|
|
|
HI the above code is marvelous..
But it lacks one major feature...That is sending the OLE objects as attachements. Do u have any idea how to proceed in this particualr area. I know that it involves setting PR_ATTACH_METHOD as ATTACH_OLE.
But My doubt is how exactly to convert the Variant object(passed from Outlook) into a stream...
|
|
|
|
|
The easy way
Just add this code:
/*********Attachmentt*************/
LPATTACH pAtt = NULL;
ULONG ulAttNum=0;
if (FAILED(hr = m_pMessage->CreateAttach( NULL, (ULONG)0, &ulAttNum, &pAtt)))
return false;
enum {METHOD,RENDERING,PATH, FILENAME, DISPLAYNAME, NUM_ATT_PROPS};
SPropValue spvAttach[NUM_ATT_PROPS];
spvAttach[METHOD].ulPropTag = PR_ATTACH_METHOD;
spvAttach[METHOD].Value.l = ATTACH_BY_REFERENCE;
spvAttach[RENDERING].ulPropTag = PR_RENDERING_POSITION;
spvAttach[RENDERING].Value.l = -1;
spvAttach[PATH].ulPropTag = PR_ATTACH_PATHNAME;
spvAttach[PATH].Value.lpszA ="File path";
spvAttach[FILENAME].ulPropTag = PR_ATTACH_FILENAME;
spvAttach[FILENAME].Value.lpszA = "Your file.ext";
spvAttach[DISPLAYNAME].ulPropTag = PR_DISPLAY_NAME;
spvAttach[DISPLAYNAME].Value.lpszA = "Great code.txt";
// Save the properties we have set on the attachment
if (FAILED(hr = pAtt ->SetProps(
NUM_ATT_PROPS,
(LPSPropValue)&spvAttach,
NULL)))
return false;
if (FAILED(hr = pAtt->SaveChanges(0)))
return false;
Before:
if (bHighImportance)
{
prop.ulPropTag = PR_IMPORTANCE;
prop.Value.l = IMPORTANCE_HIGH;
hr = m_pMessage->SetProps(1, &prop, NULL);
if (FAILED(hr)) return false;
}
return true;
And Thanks for that great code.
www.smartplant.cl
|
|
|
|
|
but when i used it to python , the attachment is wrong !why ??
#!/usr/bin/env python
"""module to send mail with Extended MAPI using the pywin32 mapi wrappers..."""
# this was based on Jason Hattingh's C++ code at http://www.codeproject.com/internet/mapadmin.asp
# written by David Fraser <davidf at sjsoft.com> and Stephen Emslie <stephene at sjsoft.com>
# you can test this by changing the variables at the bottom and running from the command line
from win32com.mapi import mapi
from win32com.mapi import mapitags
from stat import *
import os
import pythoncom
# Pre 2.2.1 compat.
try: True, False
except NameError: True = 1==1; False = 1==0
def SendEMAPIMail(Subject="", Message="", SendTo=None, SendCC=None, SendBCC=None, MAPIProfile=None):
"""Sends an email to the recipient using the extended MAPI interface
Subject and Message are strings
Send{To,CC,BCC} are comma-separated address lists
MAPIProfile is the name of the MAPI profile"""
# initialize and log on
mapi.MAPIInitialize(None)
session = mapi.MAPILogonEx(0, MAPIProfile, None, mapi.MAPI_EXTENDED | mapi.MAPI_USE_DEFAULT)
messagestorestable = session.GetMsgStoresTable(0)
messagestorestable.SetColumns((mapitags.PR_ENTRYID, mapitags.PR_DISPLAY_NAME_A, mapitags.PR_DEFAULT_STORE),0)
while (True):
rows = messagestorestable.QueryRows(1, 0)
if len(rows) != 1:
break
row = rows[0]
propertyid, propertyvalue = row[0]
if (propertyid == mapitags.PR_DEFAULT_STORE and propertyvalue == True):
break
# unpack the row and open the message store
(eid_tag, eid), (name_tag, name), (def_store_tag, def_store) = row
msgstore = session.OpenMsgStore(0,eid,None,mapi.MDB_NO_DIALOG | mapi.MAPI_BEST_ACCESS)
# get the outbox
hr, props = msgstore.GetProps((mapitags.PR_IPM_OUTBOX_ENTRYID), 0)
(tag, eid) = props[0]
outboxfolder = msgstore.OpenEntry(eid,None,mapi.MAPI_BEST_ACCESS)
# create the message and the addrlist
message = outboxfolder.CreateMessage(None,0)
# note: you can use the resolveaddress functions for this. but you may get headaches
pal = []
def makeentry(recipient, recipienttype):
return ((mapitags.PR_RECIPIENT_TYPE, recipienttype),
(mapitags.PR_SEND_RICH_INFO, False),
(mapitags.PR_DISPLAY_TYPE, 0),
(mapitags.PR_OBJECT_TYPE, 6),
(mapitags.PR_EMAIL_ADDRESS_A, recipient),
(mapitags.PR_ADDRTYPE_A, 'SMTP'),
(mapitags.PR_DISPLAY_NAME_A, recipient))
if SendTo:
pal.extend([makeentry(recipient, mapi.MAPI_TO) for recipient in SendTo.split(",")])
if SendCC:
pal.extend([makeentry(recipient, mapi.MAPI_CC) for recipient in SendCC.split(",")])
if SendBCC:
pal.extend([makeentry(recipient, mapi.MAPI_BCC) for recipient in SendBCC.split(",")])
# add the resolved recipients to the message
message.ModifyRecipients(mapi.MODRECIP_ADD,pal)
iAttach = message.CreateAttach(None,0)
iAttach[1].SetProps([
(mapitags.PR_ATTACH_METHOD, mapi.ATTACH_BY_REFERENCE),
(mapitags.PR_RENDERING_POSITION, -1),
(mapitags.PR_ATTACH_LONG_FILENAME, 'c:\\0.pdf'),
(mapitags.PR_ATTACH_FILENAME, '0.pdf')
])
iAttach[1].SaveChanges(0)
message.SetProps([(mapitags.PR_BODY_A,Message),
(mapitags.PR_SUBJECT_A,Subject)
])
CLEAR_READ_FLAG = 4
message.SetReadFlag(CLEAR_READ_FLAG)
message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)])
# save changes and submit
outboxfolder.SaveChanges(0)
message.SubmitMessage(0)
def test():
MAPIProfile = "outlook"
SendTo = "xxx@sina.com"
SendCC = None
SendBCC = None
SendMessage = "testing one two three"
# SendSubject = "Testing Simple MAPI!!"
# SendMAPIMail(SendSubject, SendMessage, SendTo, MAPIProfile=MAPIProfile)
SendSubject = "Testing Extended MAPI!!"
print SendSubject
SendEMAPIMail(SendSubject, SendMessage, SendTo, MAPIProfile=MAPIProfile)
if __name__ == '__main__':
MAPIProfile = ""
# Change this to a valid email address to test
SendTo = "cxl2253@sina.com.cn"
SendMessage = "testing one two three"
SendSubject = "Testing Extended MAPI!!"
SendEMAPIMail(SendSubject, SendMessage, SendTo, MAPIProfile=MAPIProfile)
|
|
|
|
|
Hi All,
I am trying to get SMTP email address using MAPI functions in VB.
So far, I am not successful in getting that.
Here is what I am doing:
1. Use MAPILogon to get MAPI session handle,
2. Use BMAPIAddress to show address selection dialog box with session
handle got in step 1 above.
3. Select 3/4 addresses in that dialog box and click "To:" to copy the names
to "To:" edit control and click OK.
4. Use ResolveName to get properties of recipients selected in step 3.
5. I should have smtp email address in Address attribute of recipient.
I am getting address internal to Outlook, but not smtp(xxx@yyy.com) in step 5.
Can anyone please tell me, how I can get smtp address using above approach
if possible? If not, are there any other techniques to get SMTP address using
MAPI functions?
Thanks in advance,
Reddy
|
|
|
|
|
I'm having the same problem! I'm trying to obtain an SMTP address from the GAL using the MAPISession and MAPIMessages ActiveX controls, and I keep getting some kind of Exchange specific addresses (not SMTP).
Did you ever find a workaround for this?
Thanks!
|
|
|
|
|
I need get the EntryId from a Exchange Message in c++. I can get it in Visual Basic correctly, but in c++ I obtain a different value. Why?.
This is my code:
------------------------------------------------------------------------------
for (ULONG ulIndex = 0; ulIndex < row->cValues; ulIndex++)
{
SPropValue *lpProp = &row->lpProps[ulIndex];
if (PR_ENTRYID == lpProp->ulPropTag)
{
printf("Estoy en PR_ENTRYID");
SBinary *sTipoBin = (SBinary *)&lpProp->Value.bin;
char s[200];
sprintf(s,"longitud=%d",(int)lpProp->Value.bin.cb);
printf("",s);
char *sEntryId = new char[lpProp->Value.bin.cb*2+1];
memset (sEntryId,0, lpProp->Value.bin.cb*2+1);
for (ULONG i=0; i<lpProp->Value.bin.cb; i++)
{
sprintf (s, "i= %d, valor = %d", i, lpProp->Value.bin.lpb[i]);
sprintf(s,"%2.2X",lpProp->Value.bin.lpb[i] & 0xFF);
strcat(sEntryId,s);
}
printf("sEntryId:",sEntryId);
}
}
-----------------------------------------------------------
The real size of EntryID is 70 but with my code I get only 40 and the value is different comparing Visual Basic and C++.
Thanks in advance.
|
|
|
|
|
Hello
I have the same problem with the EntryID ....
How convert from vb Cstring EntryId to c++ EntryId ?
|
|
|
|
|
The size of EntryID in VB is different from EntryID in C++!!
in VB they use the ascii version of the EntryID, in C++ they use binary form (Like UUEncoding)
U can convert between the two using some mapi functions!
Mads "Mazzachre" Randstoft
IntraVision - Insight Business
|
|
|
|
|
When i modify the code for unicode
value.lpszA parameter doesnot contain any value.
value.lpszw also doesnt work
how to make it unicode compliant.
|
|
|
|
|
Unfortunately, I was not able to work with Exchange Server 5.5 using MAPI in UNICODE. It simply failed when I called MAPIInitialize or tried to connect to a message store (do not remember exactly). I do not know if Exchange 2000 will react the same way.
In my case I implemented a regular (not Unicode) DLL for connecting to MAPI and Exchange Server returns encoded Unicode characters in most of MAPI properties. It encodes them as in HTML: "{"
--
Best Regards,
Andrew
|
|
|
|
|
I have the same problem, if you have resolved this I would like to know how
Thanks
Alex
|
|
|
|
|
hr = MAPIAllocateBuffer(nBufSize, (LPVOID FAR *)&pal)
is called without
MAPIFreeBuffer
|
|
|
|
|
if (FAILED( m_pSession->GetMsgStoresTable(0, &m_pMsgStoresTable) )) return false;
ist called twice in the same method (GetPointers)
Solution:
Remove one call
|
|
|
|
|
Hi Pals
This might be a simple one for most of you!
I am trying to send an email using CDO NTS, with the following code
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "myname@yahoo.com"
objMail.Body = "Test Email"
objMail.From = "myname@yahoo.com"
objMail.Subject="Test Email"
objMail.BodyFormat=0
objMail.Send
Set objMail = nothing
the mail is not sent when i execute the above code, i checked for SMTP services on my machine, which is a WIN 2K server in my office network.
what might be the problem?
I tried executing the same code from my home machine and it worked perfectly...
any suggestions as why its not working???
Thanks for your help in advance
Jon.
|
|
|
|
|
Hi,
I use Microsoft VC++ 6.0 with a MFC application (dialog oriented, done with the wizard). I've included your MAPI Wrapper and it's compiled and linked successfully. well, when i go to execute the program an error dialog is showed, it says: "not found the ordinal 23 in the dinamic link library MAPI32.dll". In others occasions not found the ordinal 19 or 21, but generally is 23. If i push Accept, others error dialogs appears, it says "DM0025: Error attaching to proccess" and "Could not execute: Path not found (Win32 error 3)"
I don't have changes in MAPI wrapper, and the files (both .cpp and both .h) are included in the visual C++ proyect.
I suspect that can be the line '#pragma comment ( lib, "mapi32" )' in MAPIAdmin.h, but i have prove to assign the absolute path, adding extension .lib, delete it...etc and nothing!
Please, i need help , somebody have any ideas.
Very thanks in advance.
José.
|
|
|
|
|
What eMail Client do use ?
Perhaps the MAPI32.dll implementation you use, does not implement all MAPI functions.
|
|
|
|
|
Hello,
i use CMapiAdmin with the attachment "extension" by Alex. It works great. But when i try to send more than one message orgap32 alerts that the address provider could not be loaded.
After i accept this alert, the mail will be send.
But i want to send more than one message without any prompt.
Can you help me, please?
Thanks a lot,
Sebastian
Sebastian.Lehmann@dlf3.siemens.de
|
|
|
|
|
Using the class CMapiAdmin, and the own one can do only the following: just put the message in the Outbox and it leaves ther - not sent. How can I sent the letter?
The problem ocuurs only in the full Outlook - not in the Outlook Express or other mail Clients.
The problem ocuurs when using simple MAPI and Extended MAPI as well.
I will appriciate any help/source code/advise.
mailto: dao@dreamsoft.ssft.net
Sencierly Yours Jurij Drogobitskij
|
|
|
|
|
It does send the message, but leaves it in your Outbox as well. The solution to this problem is on the very first message posted. Try hitting Next to get to the next page of messages.
|
|
|
|
|
When I try to use simple MAPI program to send email through Exchange Server, I can successfully send email when the parameter (Flags) of MAPILogon is set to MAPI_LOGON_UI (It ask me to input username, domain and password for mail server).
Can I use the program to send email without using the UI? How can I logon using username, domain and password without the UI?
Thanks,
|
|
|
|
|