使用SKPSMTPMessage发送的电子邮件附件在iOS邮件客户端中显示为联系人



我已经使用这个有用的库测试了发送附件的代码:

Skpsmtpmessage库

电子邮件似乎发送正确,当我通过hotmail或gmail客户端查看时,我会看到jpeg图像。然而,当我通过iOS邮件客户端查看同一封电子邮件时,附件显示为"联系人",单击此按钮可以选择将文件保存为新联系人。

我尝试过从hotmail发送一封带有jpeg附件的电子邮件,当我这样做时,它会正确显示在iOS客户端中。

有人知道这是代码还是iOS出错了吗?

//the guts of the message.
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = @"aname@gmail.com";
testMsg.toEmail = @"aname@gmail.com";
testMsg.relayHost = @"smtp.gmail.com";
testMsg.requiresAuth = YES;
testMsg.login = @"aname@gmail.com";
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;rntx-unix-mode=0644;rntname="file.jpeg"";
NSString *attachment = @"attachment;rntfilename="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];

尝试更改

 NSString *directory = @"text/directory;...

 NSString *directory = @"text/jpeg;...

我希望这对你有用!

Steffen

最新更新