sharatha / skpsmtpmessage

Automatically exported from code.google.com/p/skpsmtpmessage
0 stars 0 forks source link

What to change to attach JPEG file #39

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I tried attaching a 91KB jpg file and the file appears to be corrupted when 
received.  Can't open with 
iPhone or Photoshop when email to my Windows account.

I took the brute force approach of changing all vcf references to jpg and 
test.vcf to my own file 
name in the SMTPSenderAppDelegate.m file.  This apparently was not adequate.  I 
saw other people 
talking about attaching jpg files so this must be possible.

Any help is appreciated.

Original issue reported on code.google.com by francis.tse8 on 20 Oct 2009 at 10:02

GoogleCodeExporter commented 9 years ago
I did change the Content-Type to "image/jpeg" as well.  So far, I have only 
made changes on the delegate file.

Besides the email address I changed, here are the changes I made to the 
delegate file:

NSDictionary *plainPart = [NSDictionary 
dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                               @"This is a test message.  First time to send jpg 
file.",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil
];

    NSString *jpgPath = [[NSBundle mainBundle] pathForResource:@"DataView081109c" ofType:@"jpg"];
    NSData *jpgData = [NSData dataWithContentsOfFile:jpgPath];

    NSDictionary *jpgPart = [NSDictionary dictionaryWithObjectsAndKeys:@"image/jpeg;\r\n\tx-unix-
mode=0644;\r\n\tname=\"DataView081109c.jpg\"",kSKPSMTPPartContentTypeKey,
                             @"attachment;\r\n\tfilename=\"DataView081109c.jpg\"",kSKPSMTPPartContentDispositionKey,[jpgData 
encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransfe
rEncodingKey,nil];

My changes did appear to do the correct thing to the MIME header.  See info 
captured on the debug console:

--SKPSMTPMessage--Separator--Delimiter
Ä

Original comment by francis.tse8 on 21 Oct 2009 at 11:03

Attachments:

GoogleCodeExporter commented 9 years ago
Somehow, the funny characters after the Delimiter cause the text not to be 
copied.  Here it is again without the funny 
characters:

2009-10-21 16:36:25.706 SMTPSender[2742:207] C: Content-Type: text/plain
Content-Transfer-Encoding: 8bit

This is a test message.  First time to send jpg file.
--SKPSMTPMessage--Separator--Delimiter
Content-Disposition: attachment;
    filename="DataView081109c.jpg"
Content-Type: image/jpeg;
    x-unix-mode=0644;
    name="DataView081109c.jpg"
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAgEASABIAAD/4RXLRXhpZgAATU0AKgAAAAgADQEPAAIAAAAGAAAAqgEQAAIAAAAH
AAAAsAESAAMAA
AABAAEAAAESAAMAAAABAAEAAAEaAAUAAAABAAAAuAEbAAUAAAABAAAAwAEoAAMAAAABAAIAAAExAAIAA
AAQAAAAyA
EyAAIAAAAUAAAA2AE8AAIAAAAQAAAA7AITAAMAAAABAAEAAIdpAAQAAAABAAAA/Ig

Original comment by francis.tse8 on 21 Oct 2009 at 11:07

GoogleCodeExporter commented 9 years ago
Turned out that i do not have the corruption problem if I send the attachment 
to a different email account - like 
the TimerWarner Roadrunner account.  I do not know what POP server is used for 
Roadrunner but the file is 
corrupted when send to a account using Outlook mail server.  Any idea why this 
is the case?

Original comment by francis.tse8 on 4 Nov 2009 at 4:25