Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 22
Registered: ‎01-20-2011
My Device: Bold 9650

Email with Attachment from Webworks app

We have a webworks app where users fill out a form. We would like to generate an email with what they have entered and I see how to do this here:

http://www.blackberry.com/developers/docs/widgetap​i/blackberry.message.Message.html

 

Our users also take a picture along with the data they entered. Is there a way to attach that picture as part of the email?

Or does anyone know of an existing javascript extension that I could use to do this?

I have not yet dabbled with extensions and am already over my timeframe and budget for this project - this is the last challenge I have to overcome. I hope there is some solution already out there. Any help would be greatly appreciated.

Thanks

Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: Email with Attachment from Webworks app

Hi HarrietNY,

 

There is an issue open in github to track this problem https://github.com/blackberry/WebWorks/issues/26



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Contributor
Posts: 22
Registered: ‎01-20-2011
My Device: Bold 9650

Re: Email with Attachment from Webworks app

Thanks, jeffheifetz that answers part of my question. I was pretty sure that the API could not do it. But, perhaps anyone knows of an existing JavaScript Extension I could use?

Thanks

Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: Email with Attachment from Webworks app

Hi HarrietNY,

 

I've heard a bunch of people complain about it, but never seen any extensions that actually fix it, sorry.



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Contributor
Posts: 22
Registered: ‎01-20-2011
My Device: Bold 9650

Re: Email with Attachment from Webworks app

That's too bad.

Thank you for the quick responses!

New Contributor
Posts: 7
Registered: ‎05-25-2012
My Device: Torch 9850

Re: Email with Attachment from Webworks app

Did this ever get resolved?  I'm trying to do the same thing and I haven't found anything about sending an email with an attachment in WebWorks.

Trusted Contributor
Posts: 134
Registered: ‎04-15-2012
My Device: Bold 9900

Re: Email with Attachment from Webworks app

The way I managed to do this is the github blackberry webworks community apis - File Uploader. Have the form & image submit to a web service and route it from there.
New Contributor
Posts: 7
Registered: ‎05-25-2012
My Device: Torch 9850

Re: Email with Attachment from Webworks app

I wrote this Javascript Extension that is able to send an email with an attachment.  It probably has some bugs and I should handle errors better and whatnot, but it has gotten the job done for me.  Tested on Torch 9850.

 

package sample;

import net.rim.device.api.script.ScriptableFunction;
import net.rim.device.api.system.Alert;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.Connector;
import java.io.DataInputStream;
import java.io.InputStream;
import net.rim.device.api.io.IOUtilities;
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.mail.MessagingException;
import net.rim.blackberry.api.mail.Multipart;
import net.rim.blackberry.api.mail.SupportedAttachmentPart;
import net.rim.blackberry.api.mail.TextBodyPart;
import net.rim.blackberry.api.mail.Folder;
import net.rim.blackberry.api.mail.Address;
import net.rim.blackberry.api.mail.Transport;
import net.rim.blackberry.api.mail.Session;
import net.rim.device.api.ui.component.Dialog;

public final class Vibrate extends ScriptableFunction
{
    public Object invoke(Object obj, Object[] args) throws Exception
    {

        	//input = (email address, subject, body, full attachment path)
        	       	
		    String email = (String)args[0].toString();
		    String subject = (String)args[1].toString();
		    String body = (String)args[2].toString();
		    String attachment = (String)args[3].toString();
		    String fName = attachment;
		    byte[] data = null;
		    FileConnection fconn = null;
		    DataInputStream is = null;
		    fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
		    is = fconn.openDataInputStream();             
		    data = IOUtilities.streamToBytes(is);
        	    is.close();
        	    fconn.close();

          //create a multipart
            Multipart mp = new Multipart();

            //create the file
            SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"application/x-example",attachment,data);

            TextBodyPart tbp = new TextBodyPart(mp, body);

            //add the file to the multipart
            mp.addBodyPart(tbp);
            mp.addBodyPart(sap);

            //create a message in the sent items folder
            Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);

            Message message = new Message(folders[0]);
            Address toAdd = new Address(email,"my email");
            Address toAdds[] = new Address[1];
            toAdds[0] = toAdd;
            message.addRecipients(Message.RecipientType.TO, toAdds);
            message.setSubject(subject);
            message.setContent(mp);
            Session session = Session.getDefaultInstance();
            Transport trans = session.getTransport();
            //add recipients to the message and send
            try {
                 trans.send(message);
            } catch (Exception e) {
                 Dialog.inform(e.toString());
            }
        

        return UNDEFINED;
    }
}

 I left it named "Vibrate" so you can use it as shown here: Using JavaScript extension with changing "Vibrate.java" to the above code.