Rahul Vyas
Rahul Vyas

Reputation: 28750

How can I send attachments using iphone mail-core api?

I'm working on a project in which I'm using the mail-core iphone api to send and retrieve mail. I have tried a lot of things, but have been unable to find any solution. I've tried searching but haven't found any solution. Could someone explain how to use the mail-core api to send attachments?. If anybody knows how to do that please let me know.

Upvotes: 0

Views: 1480

Answers (2)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

I haven't tested this but if you look at the header for CTCoreMessage, it does have a method addAttachment:. Argument for this is a CTCoreAttachment object.

Upvotes: 2

Denis Kutlubaev
Denis Kutlubaev

Reputation: 16204

Add this only and only after you setBody or setHTMLBody:

// Set Attachments
NSString *filePrefix = [[NSBundle mainBundle] bundlePath];
NSString *path = [NSString stringWithFormat:@"%@/%@",filePrefix,@"TestData/DSC_6201.jpg"];
NSLog(@"path:%@", path);

CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
if ([attach data]==nil) {
    NSLog(@"Error: attachment data is nil");
}
[myMessage addAttachment:attach];

Here, you should add TestData folder with image to your project as a folder reference

Upvotes: 1

Related Questions