login about faq

I am developing an email client using Chilkat Email Client Library. Many times users drag and drop images in the email body and send the email. Is there any API to retrieve/show such images?

asked Jul 07 '14 at 07:22

Bhagyashree's gravatar image

Bhagyashree
1613


Hi! You should use related items of image MIME type. Chilkat Email object contains related items and related items count. I use C# but I think that in your case code wil be the same.

link

answered Jul 08 '14 at 03:17

kuligintim's gravatar image

kuligintim
316911

Well I used the following to embed images in my WebView:

#import <AssetsLibrary/AssetsLibrary.h> /// REMEMBER TO ADD FRAMEWORK TO LINKER

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Obtain the path to save to
    NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

    // Get selected image filename
    __block NSString *imagePath = nil;
    NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset) {
        ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
        // Get path with filename at end
        imagePath = [documentsDirectory stringByAppendingPathComponent:[imageRep filename]];

        // Save the selected image inside the app
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSData *data = UIImagePNGRepresentation(image);

        // If image is saved, insert the image from correct path
        if ([data writeToFile:imagePath atomically:YES]) {
            // Embed the image into the webview (email)
            NSString *imageTag = [NSString stringWithFormat:@"\n<img src=\"%@\" width=\"100%%\"><br><br>", imagePath];
            NSString *oldHTML = [_emailBodyWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"];
            NSString *newHTML = [NSString stringWithFormat:@"<html contenteditable=\"true\">%@%@</html>", oldHTML, imageTag];
            NSLog(@"\n\n NEW HTML: \n\n%@ \n\n >>> \n\n", newHTML);
            [_emailBodyWebView loadHTMLString:newHTML baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
            [_embededImages addObject:@{@"ImagePath": imagePath, @"ImageTitle": [imageRep filename]}];
        } else {
            NSLog(@"Couldn't save photo to Documents directory!");
            [picker dismissViewControllerAnimated:YES completion:nil];
            return;
        }

        // Dismiss Photo Picker
        [picker dismissViewControllerAnimated:YES completion:^{ [_emailBodyWebView reload]; }];
    };
    ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
}

In your "Sending Email Method":

NSLog(@"_embededImages: %@", _embededImages);

CkoEmail *email = [[CkoEmail alloc] init];  
for (int x = 0; x < images.count; x++) {
    NSString *imagePath = [[_embededImages objectAtIndex:x] valueForKey:@"ImagePath"];
    NSString *imageTitle = [[_embededImages objectAtIndex:x] valueForKey:@"ImageTitle"];
    [email AddRelatedFile2:imagePath filenameInHtml:imageTitle];
}

Few problems here. When embedding images, the title will be the imagePath name, if you twist them they wont work lol but you can play around with this as I just stopped using embedded images and will do everything as attachments only.

If you added the images, and delete them from WebView, they will still be in the "_embededImages" array for sending, so when you delete the images, it will still send.

I pasted this to help you, so feel free to continue and finish it off as I won't continue with embedded images. Hope this helps a little. :)

link

answered Jul 20 '14 at 18:47

emotality's gravatar image

emotality
462410

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×94
×12

Asked: Jul 07 '14 at 07:22

Seen: 1,371 times

Last updated: Jul 20 '14 at 18:47

powered by OSQA