Search code examples
androidiosactionscript-3apache-flexflash-builder

Send an email from a flex app on both android and Iphone


Using flash builder I have developed an app for both android and IPhone. I would like to be able to open the default email client on the phone and send an email with an attachment. I have seen many examples using "mailto:" however this is not supported with an attachment. I have googled this extensively and have found nothing that is current with in the last 3 years.

I already make the pdf file I wish to attach and can move it to a temp directory if needed to satisfy the access issue. I would like to use the default mailer like other programs use if that is not doable please tell me how to directly send an email from the app.


Solution

  • Just for reference to help expand the Action Script 3.0 Information base. I was unable to find any way to do what I was asking above. Here is the Method that I used to send email with attachment. https://code.google.com/p/airxmail/
    http://flex.coltware.com/as3-flex-air/airxmail/

    import com.coltware.airxmail.INetAddress;
    import com.coltware.airxmail.MailSender.SMTPSender;
    import com.coltware.airxmail.MimeMessage;
    import com.coltware.airxmail.RecipientType;
    
    private function send_plain_email():void{
    //  How to send plain text email
    var sender:SMTPSender = new SMTPSender();
    sender.setParameter(SMTPSender.HOST,"your.smtp.hostname");
    sender.setParameter(SMTPSender.PORT,25);  // default port is 25
    // If you use SMTP-AUTH
    sender.setParameter(SMTPSender.AUTH,true);
    sender.setParameter(SMTPSender.USERNAME,"username");
    sender.setParameter(SMTPSender.PASSWORD,"password");
    
    // Create email message
    var message:MimeMessage = new MimeMessage();
    
    //  Set from email address and reciepients
    var from:INetAddress = new INetAddress("from-email-address@xxxx.yyyy","from label");
    message.setFrom(from);
    
    var toRecpt:INetAddress = new INetAddress("to-email-address@xxxx.yyyy","to label");
    message.addRcpt(RecipientType.TO,toRecpt);
    
    var ccRecpt:INetAddress = new INetAddress("cc-email-address@xxxx.yyyy","cc label");
    message.addRcpt(RecipientType.CC,ccRecpt);
    
    //  
    message.setSubject("hello world");
    //
    //  Plain Text Part
    //
    var textPart:MimeTextPart = new MimeTextPart();
    message.setSubject("Reciept for #" + job.jobs.JobID);
    textPart.contentType.setParameter("charset","UTF-8");
    textPart.transferEncoding = "8bit";
    textPart.setText("Please see attached PDF \n You will need a PDF viewer to open \n To download the latest version of Adobe Acrobat reader, Please follow the link: http://www.adobe.com/products/acrobat/readstep.html");
    message.addChildPart(textPart);
    
    //
    //  Attachment part 
    //
        var filePart:MimeImagePart = new MimeImagePart();
        filePart.contentType.setMainType("application");
        filePart.contentType.setSubType("pdf");
               filePart.setAttachementFile(File.desktopDirectory.resolvePath(sfile),"WorkOrder.pdf");
                message.addChildPart(filePart);
    
                sender.send(message);
                sender.close();
    }