无法通过SKPSMTPMessage在电子邮件附件中正确发送pdf文件

时间:2014-01-09 06:55:20

标签: ios xcode pdf email-attachments

我有问题通过SKPSMTPMessage在电子邮件附件中正确发送pdf文件。我只能在网络邮件中打开它,而不能在Mac中的Mail或Windows中的Outlook中打开它。发送前文件正确。但是当我在Mac的Mail程序中打开它时,它会抱怨该文件已损坏。我确信在发送邮件时我犯了一些错误。 你能帮我看看邮件发送有什么问题吗?非常感谢你的帮助!

 SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail       = @"xxxx";
testMsg.toEmail         = @"xxxx";

testMsg.relayHost       = @"xxxxxxx";
testMsg.requiresAuth    = YES;
testMsg.login           = @"xxxx";
testMsg.pass            = @"****";
testMsg.subject         = @"ppp";
testMsg.wantsSecure     = YES; 

testMsg.delegate = self;

//email contents
NSString * bodyMessage = [self getBodyMessage];  //this is just a function to make up mail content

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                           bodyMessage ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

NSMutableArray* parts   = [[NSMutableArray alloc] init];
[parts addObject:plainPart];

    //send simple order
    NSString* fileName  = self.companyOrder.simpleOrder.pdfFileName;
    NSString *filePath  = self.companyOrder.simpleOrder.pdfFileLocation;
    NSData *fileData    = [NSData dataWithContentsOfFile:filePath];

    NSString* strFormat = [NSString stringWithFormat:@"application/pdf;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"", fileName];

    NSString* strFormat2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"", fileName];

    NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:
                             strFormat,kSKPSMTPPartContentTypeKey,
                             strFormat2,kSKPSMTPPartContentDispositionKey,
                             [fileData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];


    [parts addObject:vcfPart];

// Send the email with the plain part and message
testMsg.parts = parts;

[testMsg send];

0 个答案:

没有答案