1

how to add files to the message using smtp sender example such as here:

Locking the Fields in MFMailComposeViewController

Community
  • 1
  • 1

3 Answers3

0

You can use this fork of SKSMTPMessage: https://github.com/jetseven/skpsmtpmessage

There is a demo project that send email with files, review this source file: https://github.com/jetseven/skpsmtpmessage/blob/master/Demo/Classes/SMTPSenderAppDelegate.m

You need these lines:

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];

Where testMsg is an instance of SKPSMTPMessage class

Vitaly S.
  • 2,389
  • 26
  • 40
0

if I do this, it will attach the pdf file and PNG file to the letter?

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:@"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];
0

I've just found another library for sending e-mail on iOS: MailCore

There is an special class for adding attachments to emails: CTCoreAttachment

Vitaly S.
  • 2,389
  • 26
  • 40