0
我已經測試的代碼使用這個有用的庫發送附件iOS郵件客戶端:電子郵件附件顯示作爲接觸
電子郵件似乎被正確發送,當我查看通過hotmail或Gmail客戶端,我可以看到jpeg圖像。但是,當我通過iOS郵件客戶端查看同一封電子郵件時,附件顯示爲「聯繫人」,然後單擊此選項可以選擇將該文件另存爲新聯繫人。
我試過用hotmail發送帶有jpeg附件的電子郵件,當我這樣做時,它在iOS客戶端中顯示正確。
有誰知道這是代碼還是iOS錯誤?
//the guts of the message.
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = @"[email protected]";
testMsg.toEmail = @"[email protected]";
testMsg.relayHost = @"smtp.gmail.com";
testMsg.requiresAuth = YES;
testMsg.login = @"[email protected]";
testMsg.pass = @"password";
testMsg.subject = @"The message subject";
testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!
// Only do this for self-signed certs!
// testMsg.validateSSLChain = NO;
testMsg.delegate = self;
//email contents
NSDate* now = [NSDate date];
NSString * bodyMessage = [NSString stringWithFormat:@"The message body"];
// email image if it exists
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/file.jpeg"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableArray* parts = [[NSMutableArray alloc] init];
// add plain part
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
bodyMessage ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
[parts addObject: plainPart];
// add attachments
NSData *attachmentData = [NSData dataWithContentsOfFile:jpgPath];
NSString *directory = @"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"file.jpeg\"";
NSString *attachment = @"attachment;\r\n\tfilename=\"file.jpeg\"";
NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys:
directory,kSKPSMTPPartContentTypeKey,
attachment,kSKPSMTPPartContentDispositionKey,
[attachmentData encodeBase64ForData],kSKPSMTPPartMessageKey,
@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
[parts addObject: image_part];
testMsg.parts = parts;
[testMsg send];
這項工作?我正在試圖添加一個JPEG圖像到電子郵件。似乎不適合我。 – 2012-08-02 06:09:39
我試圖在後臺線程中發送一封郵件,最終無論如何這個線程都是不允許的。我採取了使用代理服務器來中繼消息。 – Ellis 2012-08-05 20:09:21