Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email Attachments
#1
Could I get an example of working with email attachments?

Thanks,
Jimmy Vig
#2
Sending or receiving?
#3
Receiving.

Sending is simple through the email dialog...right?
#4
Macro Macro1484
Code:
Copy      Help
;download messages. This code does not delete them from server. To delete, use flag 2.
ARRAY(MailBee.Message) a
ReceiveMail("" 0 "" 0 a)

;save attachments here
str folderForAttachments.expandpath("$desktop$\folderForAttachments")
mkdir folderForAttachments

int i
for i 0 a.len ;;for each message
,MailBee.Message& m=a[i]
,;out m.Attachments.Count
,MailBee.Attachment t
,foreach t m.Attachments ;;for each attachment
,,out t.Filename
,,;out t.Content
,,if(!t.SaveFile(folderForAttachments t.Filename)) out "Failed to save"
,,
#5
Thanks. I saw the attachments member function but couldn't figure out how to use it. Thanks bunches!
#6
I have .eml file with a photo attachemnt, "photo.jpg" that is 217 KB.

When using MailBee.Attachment to SaveFile the photo doesn't save correctly.

The saved file size is only 204 KB, and when opening with IrfanView get error "Decode error ! Not a JPEG file: starts with 0x3f 0x3f"

When I open the .eml file with outlook and save the image, everything with the image works fine.

Please advise, is something wrong with the email file, the image file, or is there another way to extract images that will work?
QM forum won't allow EML extension. Should I attach a .txt version?

I've been using this method for extracting images for quite a while without any troubles.

-jim
#7
attach zip
#8
Thanks. I obviously did not think of that ;-)


Attached Files
.zip   email.zip (Size: 225.77 KB / Downloads: 465)
#9
It is bug in mailbee component. I could not find a reliable workaround. Maybe tomorrow.
#10
Thanks for looking into this for me.

It's strange that it works with most things and then screws this up.

-jim
#11
If you open raw text of the eml file, you see line

Content-Type: image/jpeg; name="testphoto.jpg"; charset="UTF-8"; method=base64

The charset="UTF-8"; should not be used here. Mailbee thinks that it is text and does some Unicode conversion. Saves correctly if I remove charset="UTF-8";.
#12
Neat.

I was wondering about the UTF-8. It didn't makes sense to me. I almost tested editing that, but I thought for sure it would be more complicated.

Lesson...always test simple things!

Thanks,
Jim
#13
Unexpected solution. Cannot explain it but works.

m.CodepageMode=1

Macro Macro1765
Code:
Copy      Help
out
str eml="$desktop$\email.eml"
;str eml="$desktop$\email - copy.eml"
eml.expandpath

;save attachments here
str folderForAttachments.expandpath("$desktop$\folderForAttachments")
mkdir folderForAttachments

MailBee.Message m._create

m.CodepageMode=1
;m.Codepage=65001

m.ImportFromFile(eml)
;out m.Attachments.Count
MailBee.Attachment t
foreach t m.Attachments ;;for each attachment
,out t.Filename
,
,if(!t.SaveFile(folderForAttachments t.Filename)) out "Failed to save"
#14
But does not work if message is already loaded, and probably will not work if message is received. Will need to get raw text of received message and set raw text of new message.

m.RawBody=receivedMessage.RawBody
#15
Adding m.CodepageMode=1 to my code worked like a charm.

Thanks.


Forum Jump:


Users browsing this thread: 1 Guest(s)