How to send email with attachment

2 posts, 0 answers
  1. Alex
    Alex avatar
    5 posts
    Member since:
    Jan 2014

    Posted 20 Jul 2014 Link to this post

    Hi,

    I would like to know how to trigger and open the native email app with attachment.

    1. I downloaded the file(s) in mobile local storage
    2. Press any button to open native email app
    3. The email draft which enclose that file(s)

    Thanks.
  2. Martin Yankov
    Admin
    Martin Yankov avatar
    177 posts

    Posted 23 Jul 2014 Link to this post

    Hi Alex,

    Thank you for contacting Telerik support.

    You should try the SocialSharing Plugin from the Verified Plugins Marketplace. Along with sharing to social media, It supports starting a mail app with all the possible mail settings, attachments etc. Once you have installed the plugin in your project and the deviceready event has fired, you can use the following piece of code to start the default email app with the corresponding mail content:
    // check for a configured email client
    window.plugins.socialsharing.canShareViaEmail([success], [error]);
      
    // share something
    window.plugins.socialsharing.shareViaEmail(
      'Message',
      'Subject',
      ['to@person1.com', 'to@person2.com'], // TO: must be null or an array
      ['cc@person1.com'], // CC: must be null or an array
      null, // BCC: must be null or an array
      ['https://www.google.nl/images/srpr/logo4w.png'], // FILES: null, a string, or an array
      onSuccess, // called when email was sent or canceled, no way to differentiate
      onError // called when something unexpected happened
    );

    As a file attachment you can also use the device file path string or the base64 string path of the file.

    On the SocialSharing Plugin page, you can click "Try Plugin in AppBuilder" and it will load the plugin's sample app where u can test the functionality.

    I hope this solution works for you. Let me know in case you experience any problems or have any further questions.

    Regards,
    Martin Yankov
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top