Sending attributes with MailCore2 on ios 8

I cannot send attachments via MailCore2. Can i use MailCore for ios 8 ?. Could you please provide me with the correct approach. I want to send docx, pdf, xls, png and jpeg files in applications

+3


source to share


3 answers


Loop through all attachments (file paths) and add them to MessageBuilder:

MCOMessageBuilder *msgBuilder = [[MCOMessageBuilder alloc] init];

NSArray *allAttachments = @[@"/var/mobile/etc..", @"/var/mobile/etc2.."];

for (int x = 0; x < allAttachments.count; x++) {
    NSString *attachmentPath = allAttachments[x];
    MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:attachmentPath];
    [msgBuilder addAttachment:attachment];
}

      



An example of the expected binding path:

"/var/mobile/Containers/Data/Application/B47D8576-B38E-4864-AC76-8EBC630B6B44/Documents/IMG_0522.JPG"

      

+5


source


To send the image as an attachment to SWIFT, simply add:



    var dataImage: NSData?
    dataImage = UIImageJPEGRepresentation(image, 0.6)!
    var attachment = MCOAttachment()
    attachment.mimeType =  "image/jpg"
    attachment.filename = "image.jpg"
    attachment.data = dataImage
    builder.addAttachment(attachment)

      

+1


source


SWIFT 3

Since I had a UIImage object, I just converted to NSData and then processed as Data! (The data is just a struct from the Foundation class)

Hope this helps!

@zepvalue

    let dataImage = UIImageJPEGRepresentation(dataStore.currentModel.signature!, 2) as NSData?
    builder.header.to = [MCOAddress(displayName: "Zepvalue", mailbox: "email@gmail.com")]
    builder.header.from = MCOAddress(displayName: "Zepvalue", mailbox: "email@gmail.com")
    attachment.mimeType = "image/jpg"
    attachment.filename = "image.jpg"
    attachment.data = dataImage as Data!
    builder.addAttachment(attachment)

      

-1


source







All Articles