1

如何使用 smtp 发件人示例将文件添加到消息中,例如:

锁定 MFMailComposeViewController 中的字段

4

3 回答 3

0

您可以使用 SKSMTPMessage 的这个分支:https ://github.com/jetseven/skpsmtpmessage

有一个使用文件发送电子邮件的演示项目,查看此源文件:https ://github.com/jetseven/skpsmtpmessage/blob/master/Demo/Classes/SMTPSenderAppDelegate.m

你需要这些行:

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                               @"This is a tést messåge.",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

NSString *vcfPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"vcf"];
NSData *vcfData = [NSData dataWithContentsOfFile:vcfPath];

NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"test.vcf\"",kSKPSMTPPartContentTypeKey,
                         @"attachment;\r\n\tfilename=\"test.vcf\"",kSKPSMTPPartContentDispositionKey,[vcfData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];

testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart,nil];

其中 testMsg 是SKPSMTPMessage类的一个实例

于 2013-02-05T12:22:06.727 回答
0

我刚刚找到了另一个用于在 iOS 上发送电子邮件的库:MailCore

有一个特殊的类用于向电子邮件添加附件:CTCoreAttachment

于 2013-03-06T11:09:46.543 回答
0

如果我这样做,它会将pdf文件和PNG文件附加到信中吗?

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, @"这是一个测试消息。",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

NSString *vcfPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSData *vcfData = [NSData dataWithContentsOfFile:vcfPath];

NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"test.pdf\"",kSKPSMTPPartContentTypeKey,
                         @"attachment;\r\n\tfilename=\"test.pdf\"",kSKPSMTPPartContentDispositionKey,[vcfData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
NSString *vcfPath1 = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
NSData *vcfData1 = [NSData dataWithContentsOfFile:vcfPath1];

NSDictionary *vcfPart1 = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"test.png\"",kSKPSMTPPartContentTypeKey,
                         @"attachment;\r\n\tfilename=\"test.png\"",kSKPSMTPPartContentDispositionKey,[vcfData1 encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart,vcfPart1,nil];
于 2013-02-06T12:23:48.103 回答