Getting the attachments in MailItem

Status
Not open for further replies.
N

nikolayds

Hi all,

I am new in outlook addin programming, so naturally I am getting a setback

right away :).

Problem: need to get the attachaments of email

Code:

(Version one - no Redemption)

Code:
Outlook::Attachments* na = pMailItem->Attachments; 
 
int count = na->Count; 
 
Outlook::Attachment* att; 
 
_variant_t inx =0; 
 
for(int t=1;t<=count; t++) 
 
{ 
 
inx = t; 
 
att = na->Item(inx); 
 
int type = att->Type; 
 
CString filename = (BSTR) att->FileName; 
 
}

This one is getting the first attachment but blows on subsequent with read

violation error.

Using redemption

Code:
IAttachmentsPtr spAttachments = spSafeMailItem->Attachments; 
 
for(int j=1; j<=spAttachments->Count; j++) 
 
{ 
 
HRESULT _thr; 
 
_variant_t inx = j; 
 
IAttachmentPtr pAttachment; 
 
_thr = spAttachments->raw_Item(inx, &pAttachment);//->get__Item(inx, 
 
&pAttachment); 
 
// getting E_UNEXPECTED 
 
if(_thr!=S_OK) 
 
{ 
 
continue; 
 
} 
 
long size = pAttachment->FileSize; 
 
CString fname = (BSTR) pAttachment->FileName; 
 
if(pAttachment->Type == 1) //ByValue 
 
{ 
 
CString path = "C:\\"; 
 
path.Append(fname); 
 
_thr = pAttachment->SaveAsFile(path.AllocSysString()); 
 
if(_thr==S_OK) 
 
{ 
 
int a = 0; 
 
} 
 
} 
 
}

Any ideas what I am doing wrong?


201001
 
N

nikolayds

I got it: using the following code instead

hr = pAttachments->raw_Item(_variant_t(j),&pAttachment);

if (hr!=S_OK)

continue;

pAttachment->Release();

_bstr_t pAttachmentName;

pAttachment->get_FileName(pAttachmentName.GetAddress());

nikolayds wrote:
> Hi all,
> I am new in outlook addin programming, so naturally I am getting a setback
> right away :).
> Problem: need to get the attachaments of email

> Code:

> (Version one - no Redemption)
>
Code:
> 	Outlook::Attachments* na = pMailItem->Attachments; 
 
> 	int count = na->Count; 
> 	Outlook::Attachment* att; 
> 	_variant_t inx =0; 
> 	for(int t=1;t<=count; t++) 
> 	{ 
> 		inx = t; 
> 		att = na->Item(inx); 
> 		int type = att->Type; 
> 		CString filename = (BSTR) att->FileName; 
> 	} 
>
> This one is getting the first attachment but blows on subsequent with read
> violation error.

> Using redemption
>
Code:
>         IAttachmentsPtr spAttachments = spSafeMailItem->Attachments; 
> 	for(int j=1; j<=spAttachments->Count; j++) 
> 	{ 
 
> 		HRESULT _thr; 
> 		_variant_t inx = j; 
 
> 		IAttachmentPtr pAttachment; 
> 		_thr = spAttachments->raw_Item(inx, &pAttachment);//->get__Item(inx, 
> &pAttachment); 
> 		// getting E_UNEXPECTED 
>                 if(_thr!=S_OK) 
> 		{ 
> 			continue; 
> 		} 
> 		long size = pAttachment->FileSize; 
> 		CString fname = (BSTR) pAttachment->FileName; 
> 		if(pAttachment->Type == 1) //ByValue 
> 		{ 
> 			CString path = "C:\\"; 
> 			path.Append(fname); 
> 			_thr = pAttachment->SaveAsFile(path.AllocSysString()); 
> 			if(_thr==S_OK) 
> 			{ 
> 				int a = 0; 
> 			} 
> 		} 
> 	} 
 
>

> Any ideas what I am doing wrong?


 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
V Outlook 2016 Multiple recurring tasks getting created Using Outlook 0
P PST file is getting huge under POP 3 Using Outlook 2
N contact notepad 'style' getting changed after clicking and running Activities Using Outlook 2
S Outlook [Online - Office365] perfomance is getting affected when accessing the mails using Redemptio Using Outlook 1
D Close Oulook after sending emails via vba without outbox getting stuck. Outlook VBA and Custom Forms 1
C im getting a type mismatch error Outlook VBA and Custom Forms 3
William getting custom form to load category colors Outlook VBA and Custom Forms 4
C Getting back previous computer owner Outlook email Using Outlook.com accounts in Outlook 1
B Recipient of a forwared message getting multiple emails Using Outlook 2
S Outlook 2010 I am getting error code 0x8DE00006 'the operation failed'. outlook 2010 send/receive progress Using Outlook.com accounts in Outlook 2
S Mails getting downloaded multiple times Using Outlook 1
Rory Campion Not getting a warning when a shared calendar item has been updated by someone else Using Outlook 2
E Getting IMAP email into existing pst file Using Outlook 6
J Just installed Outlook 2010 on computer and user is getting a 0x80004005 error Using Outlook.com accounts in Outlook 1
R Getting a colleagues appointments and calendar entries Using Outlook 1
E Getting Outlook full name correct with AddressLayout Using Outlook 1
P I'm getting an error when opening Outlook "Mobile me stopped working Using Outlook 1
D Need Help with Script. Keep getting Runtime Error 438 BCM (Business Contact Manager) 4
R Need help getting BCM to work with my Outlook 2014 Using Outlook 4
D Help Getting Started? BCM (Business Contact Manager) 4
P I am getting an error msg = cannot open file access denied Using Outlook 3
K why is a user getting email respond for invite respond that she didn't set up. Using Outlook 3
B email getting cut off Using Outlook 9
L Need help getting calendar/contacts/tasks/notes back! Using Outlook 3
M Email Format getting changed to Plain Text Using Outlook 1
G Outlook 2013: Getting meeting invites in OWA format Using Outlook 9
M Getting messages from multiple email address Using Outlook 1
B not getting email from people Using Outlook 3
L Outlook 2010 - Keep getting "Corrupted File" Msgs Using Outlook 4
mrje1 Assigned Categories keep getting deleted in mail, bug? How to fix if possible? Using Outlook 5
Commodore Why some RSS feeds stop getting updates? Using Outlook 12
M All e mails seem to be getting blocked BCM (Business Contact Manager) 7
J Send/receive getting stuck Using Outlook.com accounts in Outlook 1
R Getting my Claendar additions to appear in Outlook Today Using Outlook 7
J Getting Contact Name to show on Calendar Using Outlook 2
D outlook getting stuck receiving Using Outlook 1
Y MICROSOFT OUTLOOK 2007 - i KEEP GETTING THE "ENTER NETWORK PASSWORD" BOX POPPING UP - IT IS ALREADY Using Outlook 4
T getting an error This file does not have a program associated with it for performing this action. C Using Outlook 7
C getting the subject line out of a mail Outlook VBA and Custom Forms 2
S Trying to install BCM 2010 x64, getting error BCM (Business Contact Manager) 8
Q I cannot start Outlook 2007 I keep getting this error: __'Cannot start outlook window. Invalid XML,the view cannot be loaded.' Using Outlook 3
K Getting (internal) sender's account ID (userID) Outlook VBA and Custom Forms 2
S MAcro - Need help in getting the recipients in to filed / cc field toput in an array Outlook VBA and Custom Forms 4
C Getting Error message BCM (Business Contact Manager) 1
R getting the name of the pst file Outlook VBA and Custom Forms 2
J I'm getting an error code 8 when try to access my exchange account Using Outlook 6
A issue with the sender's name getting changed Outlook VBA and Custom Forms 1
D Getting Started - Reading attachment Outlook VBA and Custom Forms 4
H For Each loop not getting all Email Items Outlook VBA and Custom Forms 3
J Getting values of custom categories set on Calendar folder Outlook VBA and Custom Forms 2

Similar threads

Top