Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

cocoa touch - GMail won't open .txt attachment created by iPhone App, Depending on Size - I think There's a Bug in my MIME

I have created aand sent a short email with a .txt attachment in an iPhone app.

  1. If the attachment is about 10 lines long, GMail opens it just fine.

  2. If it's more than 20 or so lines, GMail chokes - it won't open the attachment, download the attachment, or even forward the email.

  3. Also, if I send the same email to my colleague and he opens it with his Mac OS Mail client, everything works fine.

For example, the following is the content of the text file (this length will open in GMail just fine):

ACCELEROMETER READINGS
-0.0724487,-0.941833,-0.235458,2009-07-11 15:18:46 -0700
-0.0724487,-0.941833,-0.271683,2009-07-11 15:18:47 -0700
-0.0724487,-0.923721,-0.253571,2009-07-11 15:18:48 -0700
-0.0543365,-0.923721,-0.326019,2009-07-11 15:18:49 -0700
-0.0724487,-0.959946,-0.181122,2009-07-11 15:18:50 -0700
-0.0543365,-0.923721,-0.253571,2009-07-11 15:18:51 -0700
-0.108673,-0.923721,-0.380356,2009-07-11 15:18:52 -0700
-0.0724487,-0.923721,-0.271683,2009-07-11 15:18:53 -0700

GPS READINGS

HEADING READINGS
211.421,2009-07-11 15:18:46 -0700
206.421,2009-07-11 15:18:49 -0700
184.421,2009-07-11 15:18:50 -0700
195.421,2009-07-11 15:18:51 -0700
198.421,2009-07-11 15:18:53 -0700

If the file is twice this size, GMail can't deal ith it, but once again Mail can. So, what might be the problem? I created the email as follows:

SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = @"[email protected]";
testMsg.toEmail = @"[email protected]";
testMsg.relayHost = @"smtp3.webfaction.com";
testMsg.requiresAuth = YES;
testMsg.login = @"andrewljohnson";
testMsg.pass = @"********";
testMsg.subject = @"iPhone Instrument Readings";
testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!
testMsg.delegate = self;

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, @"Hey Kevin,
Here are some GPS readings for you to filter.

Love, 
TrailBehind",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
NSData *fileData = [NSData dataWithContentsOfFile:fileName];    
NSDictionary *attached = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;
x-unix-mode=0644;
name="readings.txt"",kSKPSMTPPartContentTypeKey, @"attachment;
filename="readings.txt"",kSKPSMTPPartContentDispositionKey,[fileData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];

testMsg.parts = [NSArray arrayWithObjects:plainPart,attached,nil];
[testMsg send];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I suggest you use WireShark to see exactly what is being sent when you send the message. Then use a normal mail client to send the same message (again to GMail) and see what the difference is - as well as whether the attachment can then be downloaded.

My guess is that there's something not-quite-compliant about the way you're sending the message, which GMail is complaining about but your friend's SMTP server isn't. It's likely to be more to do with the server than the receiving client, IMO.

Another thing to try is hooking up an IMAP client to your GMail account - can you get the attachment then?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...