[英]Email attachment sent using SKPSMTPMessage appears in iOS mail client as contact
I have tested the code for sending attachments using this useful library: 我已经测试了使用此有用的库发送附件的代码:
Skpsmtpmessage library Skpsmtpmessage库
The email seems to get sent correctly, and when I view it through hotmail or gmail clients I see the jpeg image. 电子邮件似乎已正确发送,当我通过hotmail或gmail客户端查看电子邮件时,会看到jpeg图像。 However, when I view this same email through an iOS mail client, the attachment appears as a "contact" and clicking on this gives me the option to save the file as a new contact. 但是,当我通过iOS邮件客户端查看同一封电子邮件时,附件显示为“联系人”,单击此附件后,我可以选择将文件另存为新联系人。
I have tried sending an email with jpeg attachment from hotmail, and when I do this it appears correctly in the iOS client. 我尝试从hotmail发送带有jpeg附件的电子邮件,当我这样做时,它会正确显示在iOS客户端中。
Does anyone know whether this is the code or iOS getting it wrong? 有谁知道这是代码还是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;\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];
Try to change 尝试改变
NSString *directory = @"text/directory;...
to 至
NSString *directory = @"text/jpeg;...
I hope this works for you! 希望这对您有用!
Steffen 斯特芬
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.