【问题标题】:Email attachment sent using SKPSMTPMessage appears in iOS mail client as contact使用 SKPSMTPMessage 发送的电子邮件附件在 iOS 邮件客户端中显示为联系人
【发布时间】:2012-10-10 15:24:22
【问题描述】:

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

Skpsmtpmessage library

电子邮件似乎已正确发送,当我通过 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;\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 图像添加到电子邮件中。似乎对我不起作用。
  • 我试图在后台线程中发送一封电子邮件,但最终还是被拒绝了。我求助于使用代理服务器来中继消息。

标签: ios email smtp


【解决方案1】:

尝试改变

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

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

我希望这对你有用!

史蒂芬

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2010-11-09
    • 2016-08-18
    • 2015-09-02
    • 2013-04-03
    • 1970-01-01
    • 2012-11-18
    相关资源
    最近更新 更多