如何使用smtp发送器示例将文件添加到邮件中,例如:
答案 0 :(得分: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
类
答案 1 :(得分: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];
答案 2 :(得分:0)
我刚刚在iOS上发现了另一个用于发送电子邮件的库:MailCore
有一个特殊类可以为电子邮件添加附件:CTCoreAttachment