Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 24, 2017 12:43 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 2:41 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Hi,

Working with the SMTP/PoP3 Mail example files that ship with RB. Trying to add ability to receive email attachments using the Email Attachment Class. The only code sample I can locate in the LR is for adding attachments for SMTP using LoadFromFile. I can't figure out the code to get the email attachments and then use SaveToFile, which I think is the method needed to save the attachments. I suspect that it would be added to Socket1's messagerecieved, but I'm not sure.

Any help or sample for PoP3 including getting/saving attachments would be much appreciated.

Kind Regards,

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 3:08 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
In MessageReceived, you get an EmailMessage object. That object has an Attachments property, which is an array of EmailAttachment. EmailAttachment has a SaveToFile method. So you might code it like

dim f as FolderItem = GetFolderItem(...)
Message.Attachments(0).SaveToFile(f)


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 3:34 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Hi Tim,

Thanks for this. I can try to see how to apply it.

So far, a little lost as to where and how. I tried, without success:

messagereceived for PoP3 Socket

dim s as string

// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText
end

bodyFld.text = replaceAll(s,chr(13)+chr(10),chr(13))
dim f as FolderItem = GetFolderItem ("")
email.attachments(0) = SaveToFile(f)

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 3:53 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
What is "email" in your example?

In the MessageReceived event, you are handed an EmailMessage, Message. To get the first attachment, use

Message.Attachments(0)

Of course, you should test to make sure there is an attachment first.


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 5:07 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Hi Tim,

Tried different code combinations in message received, like:

dim s as string
dim mail as emailMessage
// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText
end

bodyFld.text = replaceAll(s,chr(13)+chr(10),chr(13))

dim f as FolderItem = GetFolderItem ("C:\Desktop\")
mail.Attachments(0) = SaveToFile(f)


No joy yet. Will keep reading LR, look for examples. Must be getting closer, as bug messages are moving down the code. :)

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 7:26 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
timhare wrote:
Message.Attachments(0).SaveToFile(f)


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:09 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Hi Tim,

Oooh! I'm still not getting it.

In the email example that ships with RB, the PoP3 has message received. In there currently is the following code:

dim s as string

// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText
end

bodyFld.text = replaceAll(s,chr(13)+chr(10),chr(13))


If I add the following, I get an error debugging message that this method or property does not exist, pointing either at at the dim f as FolderItem (if I leave out the conditional if statement) or pointing at the if statement:

dim f as FolderItem = GetFolderItem ("C:\Desktop\")
if Message.Attachments <> Null then
Message.Attachments(0).SaveToFile(f)
end if


Absent better understanding of the folder item (from reading in the LR, I am assuming this is a function), I am thinking that this must be the folder location to store the email attachment-attachment 0 or first one in an array. So, I am trying to define a folder location, check if there is an attachment and if not Null, get the attachment and save it there. Seems logical. Just can't seem to get it to happen.

I'll keep at it.

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Last edited by writer on Thu Jun 03, 2010 8:15 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:13 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
Try this
dim s as string

// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText
end

bodyFld.text = replaceAll(s,chr(13)+chr(10),chr(13))

dim f as folderitem = specialfolder.desktop.child("text.txt")

dim b as boolean = true

b = email.attachments(0).savetofile(f)


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:23 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Thanks, serd83.

That worked! It saved the email attachment to the desktop.

Now, moving forward, I am going to try a few variations (like getting 2 text file attachments, decrypting them with the crypto DLL, changing their save folder location).

Kind Regards,

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:26 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
To avoid errors when there is no attachment, change the line from
b = email.attachments(0).savetofile(f)

to
if ubound(email.attachments) >= 0 then b = email.attachments(0).savetofile(f)

And
dim b as boolean = true

you can change also to
dim b as boolean


Last edited by serd83 on Thu Jun 03, 2010 8:31 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:30 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Thanks again serd83.

You must have read my mind. I was just about to write to ask, based on what Tim said above, how to check if there is an attachment as part of this.

When I make these changes, I get errors:

dim s as string

// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText
end

bodyFld.text = replaceAll(s,chr(13)+chr(10),chr(13))

dim f as folderitem = specialfolder.desktop.child("text.txt")

dim boolean as boolean = true
dim boolean as boolean

if ubound(email.attachments) >= 0 then b = email.attachments(0).savetofile(f)


I must be doing something wrong.

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:41 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
As you see I edit my last post. It was forum-code, therefore. Remove both lines and use
dim b as boolean


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Thu Jun 03, 2010 8:58 pm 
Offline

Joined: Wed Jan 31, 2007 9:01 am
Posts: 273
Location: Saratoga Springs, NY area
Hi serd83.

OK, I got it right.

Thanks again.

_________________
writer

Windows 7 Home Premium 64 bit, Core i7, 8G RAM, ATI Radeon HD5770, Release 2011r3


Top
 Profile  
Reply with quote  
 Post subject: Re: PoP3 Receive email attachments
PostPosted: Mon Feb 25, 2013 12:36 am 
Offline

Joined: Mon Feb 25, 2013 12:15 am
Posts: 1
I am trying to do the same thing i.e check email client and save email attachments
Please help me


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group