Parsing email attachments using Javamail

Hi All,
I'm working on a multimedia application where I have to parse emails using Javamail.
Here is a problem that i'm facing.
When i'm receiving an attachment from icloud.com, i'm not able to get the filename whereas i'm able to get the fileSize and fileContent.
I'm using Part.getFileName() to get the file name. and Part.getFileSize() and Part.getInputStream() to get size and the content.
When i checked the attachment header, I could see the name encoded in ISO-8859-1.
--Boundary_(ID_kS5Ng+OB35IVBfC+scPoMA)
Content-id:[email protected]
Content-type:image/jpeg;
name*1*=utf-8"%20%32%33%30%32%32%30%31%33%37%32%35;
name*2*=%2E%6A%70%67
Content-transfer-encoding:BASE64
Content-disposition:inline;
filename*1*=utf-8"%20%32%33%30%32%32%%30%32%33%37%32%35
filename*2*=%2E%6A%70%67
In both the cases above, Part.getFileName() is returning null.
I set the parameter mail.mime.decodeparameters="true".Still it is not working.
It would be great if someone can suggest a solution for this.
Thanks
Shyama

Just adding to the problem description:
--Boundary_(ID_kzWHPgILjZtH2UtdriatGg)
Content-id: <[email protected]>
Content-type: image/jpeg; name*1*=ISO-8859-1''%32%2E%6A%70%67
Content-transfer-encoding: BASE64
Content-disposition: inline; filename*1*=ISO-8859-1''%32%2E%6A%70%67
This is the header which could see in another mail.

Similar Messages

  • Sending Attachments using JavaMail

    I trying to send attachments using JavaMail API which is loaded into an oracle 8.1.7 database as a stored procedure, the code looks like this:-
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "SendMail" AS
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SendMail {
    // Sender, Recipient, CCRecipient, and BccRecipient are comma-
    // separated lists of addresses;
    // Body can span multiple CR/LF-separated lines;
    // Attachments is a ///-separated list of file names;
    public static int Send(String SMTPServer,
    String Sender,
    String Recipient,
    String CcRecipient,
    String BccRecipient,
    String Subject,
    String Body,
    String ErrorMessage[],
    String Attachments) {
    // Error status;
    int ErrorStatus = 0;
    // create some properties and get the default Session;
    Properties props = System.getProperties();
    props.put("mail.smtp.host", SMTPServer);
    Session session = Session.getDefaultInstance(props, null);
    try {
    // create a message;
    MimeMessage msg = new MimeMessage(session);
    // extracts the senders and adds them to the message;
    // Sender is a comma-separated list of e-mail addresses as
    // per RFC822;
    InternetAddress[] TheAddresses =
    InternetAddress.parse(Sender);
    msg.addFrom(TheAddresses);
    // extract the recipients and assign them to the message;
    // Recipient is a comma-separated list of e-mail addresses
    // as per RFC822;
    InternetAddress[] TheAddresses =
    InternetAddress.parse(Recipient);
    msg.addRecipients(Message.RecipientType.TO,
    TheAddresses);
    // extract the Cc-recipients and assign them to the
    // message;
    // CcRecipient is a comma-separated list of e-mail
    // addresses as per RFC822;
    if (null != CcRecipient) {
    InternetAddress[] TheAddresses =
    InternetAddress.parse(CcRecipient);
    msg.addRecipients(Message.RecipientType.CC,
    TheAddresses);
    // extract the Bcc-recipients and assign them to the
    // message;
    // BccRecipient is a comma-separated list of e-mail
    // addresses as per RFC822;
    if (null != BccRecipient) {
    InternetAddress[] TheAddresses =
    InternetAddress.parse(BccRecipient);
    msg.addRecipients(Message.RecipientType.BCC,
    TheAddresses);
    // subject field;
    msg.setSubject(Subject);
    // create the Multipart to be added the parts to;
    Multipart mp = new MimeMultipart();
    // create and fill the first message part;
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setText(Body);
    // attach the part to the multipart;
    mp.addBodyPart(mbp);
    // attach the files to the message;
    if (null != Attachments) {
    int StartIndex = 0, PosIndex = 0;
    while (-1 != (PosIndex = Attachments.indexOf("///",
    StartIndex))) {
    // create and fill other message parts;
    MimeBodyPart mbp = new MimeBodyPart();
    FileDataSource fds =
    new FileDataSource(Attachments.substring(StartIndex,
    PosIndex));
    mbp.setDataHandler(new DataHandler(fds));
    mbp.setFileName(fds.getName());
    mp.addBodyPart(mbp);
    PosIndex += 3;
    StartIndex = PosIndex;
    // last, or only, attachment file;
    if (StartIndex < Attachments.length()) {
    MimeBodyPart mbp = new MimeBodyPart();
    FileDataSource fds =
    new FileDataSource(Attachments.substring(StartIndex));
    mbp.setDataHandler(new DataHandler(fds));
    mbp.setFileName(fds.getName());
    mp.addBodyPart(mbp);
    // add the Multipart to the message;
    msg.setContent(mp);
    // set the Date: header;
    msg.setSentDate(new Date());
    // send the message;
    Transport.send(msg);
    } catch (MessagingException MsgException) {
    ErrorMessage[0] = MsgException.toString();
    Exception TheException = null;
    if ((TheException = MsgException.getNextException()) !=
    null)
    ErrorMessage[0] = ErrorMessage[0] + "\n" +
    TheException.toString();
    ErrorStatus = 1;
    return ErrorStatus;
    show errors java source "SendMail"
    CREATE OR REPLACE PACKAGE SendMailJPkg AS
    -- EOL is used to separate text line in the message body;
    EOL CONSTANT STRING(2) := CHR(13) || CHR(10);
    TYPE ATTACHMENTS_LIST IS
    TABLE OF VARCHAR2(4000);
    -- high-level interface with collections;
    FUNCTION SendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING DEFAULT '',
    BccRecipient IN STRING DEFAULT '',
    Subject IN STRING DEFAULT '',
    Body IN STRING DEFAULT '',
    ErrorMessage OUT STRING,
    Attachments IN ATTACHMENTS_LIST DEFAULT NULL)
    RETURN NUMBER;
    END SendMailJPkg;
    show errors
    CREATE OR REPLACE PACKAGE BODY SendMailJPkg AS
    PROCEDURE ParseAttachment(Attachments IN ATTACHMENTS_LIST,
    AttachmentList OUT VARCHAR2) IS
    AttachmentSeparator CONSTANT VARCHAR2(12) := '///';
    BEGIN
    -- boolean short-circuit is used here;
    IF Attachments IS NOT NULL AND Attachments.COUNT > 0 THEN
    AttachmentList := Attachments(Attachments.FIRST);
    -- scan the collection, skip first element since it has been
    -- already processed;
    -- accommodate for sparse collections;
    FOR I IN Attachments.NEXT(Attachments.FIRST) ..
    Attachments.LAST LOOP
    AttachmentList := AttachmentList || AttachmentSeparator ||
    Attachments(I);
    END LOOP;
    ELSE
    AttachmentList := '';
    END IF;
    END ParseAttachment;
    -- forward declaration;
    FUNCTION JSendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING,
    BccRecipient IN STRING,
    Subject IN STRING,
    Body IN STRING,
    ErrorMessage OUT STRING,
    Attachments IN STRING) RETURN NUMBER;
    -- high-level interface with collections;
    FUNCTION SendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING,
    BccRecipient IN STRING,
    Subject IN STRING,
    Body IN STRING,
    ErrorMessage OUT STRING,
    Attachments IN ATTACHMENTS_LIST) RETURN NUMBER IS
    AttachmentList VARCHAR2(4000) := '';
    AttachmentTypeList VARCHAR2(2000) := '';
    BEGIN
    ParseAttachment(Attachments,
    AttachmentList);
    RETURN JSendMail(SMTPServerName,
    Sender,
    Recipient,
    CcRecipient,
    BccRecipient,
    Subject,
    Body,
    ErrorMessage,
    AttachmentList);
    END SendMail;
    -- JSendMail's body is the java function SendMail.Send();
    -- thus, no PL/SQL implementation is needed;
    FUNCTION JSendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING,
    BccRecipient IN STRING,
    Subject IN STRING,
    Body IN STRING,
    ErrorMessage OUT STRING,
    Attachments IN STRING) RETURN NUMBER IS
    LANGUAGE JAVA
    NAME 'SendMail.Send(java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String[],
    java.lang.String) return int';
    END SendMailJPkg;
    show errors
    var ErrorMessage VARCHAR2(4000);
    var ErrorStatus NUMBER;
    -- enable SQL*PLUS output;
    SET SERVEROUTPUT ON
    -- redirect java output into SQL*PLUS buffer;
    exec dbms_java.set_output(5000);
    BEGIN
    :ErrorStatus := SendMailJPkg.SendMail(
    SMTPServerName => 'gmsmtp03.oraclecorp.com',
    Sender => '[email protected]',
    Recipient => '[email protected]',
    CcRecipient => '',
    BccRecipient => '',
    Subject => 'This is the subject line: Test JavaMail',
    Body => 'This is the body: Hello, this is a test' ||
    SendMailJPkg.EOL || 'that spans 2 lines',
    ErrorMessage => :ErrorMessage,
    Attachments => SendMailJPkg.ATTACHMENTS_LIST(
    '/tmp/on.lst',
    '/tmp/sqlnet.log.Z'
    END;
    print
    If I try and send file as attachments from the tmp directory, then everything works ok, but if I try to send the same file from any other directory, then it doesn't work. Can anyone help? Is there something wrong with the code, I'm not aware of anything that would make it directory specfic. Permissions are the same on /tmp as the new directory /NRS/Data/SystemX which I'm trying to send the file from now.

    well
    if u see the end of ur mail it shows the attachment dir there in which u have specified the address..why don't u do a change there or better have some in parameteres in the procedure for it..that would help in choosing the attachment directory on users wish?
    hope i am getting the problem right..if not kindly correct me in understanding the problem.
    thanX.

  • Gettting attachments using JAVAMAIL

    Hi,
    I am dealing with an application which wants me to go through the mailbox and get the attachments of specific emails. These attachments are of different kinds. The attachments can vary from being rtf document, to Word, html, fo.. documents.. I got this skeleton code from the tutorial but dont know what to fill in..
    if (disposition == null) {
    // Check if plain
    MimeBodyPart mbp = (MimeBodyPart)part;
    if (mbp.isMimeType("text/plain")) {
    // Handle plain
    } else {
    // Special non-attachment cases here of
    // image/gif, text/html, ...
    What is it meant by handling plain? How do i handle html, worf, rtf documents.. Thanks a lot in advance.. Thanks
    Abhishek

    Try this as a reference. It works PERFECTLY. Ignore the comments.
    //If the content is ATTACHMENT
    filename = part.getFileName();
    if (filename != null) {
    filename = filename.trim();
    if(filename.equalsIgnoreCase(fileNameDownload.trim())) {
                                            //System.out.println("Downloading DOWN 1");
                                            session_id = this.DL_sessionid;
                                            directory = ATTACHMENTPath + m_user + "_" + session_id + "/";
                                            if(download) {
                                                 pushFile(part.getFileName(),part.getInputStream(),resp);
                                            } else {
                                                 saveFile(part.getFileName(), directory, part.getInputStream(), resp);
                                       filectr++;
         private void saveFile(String fileName, String Directory, InputStream input, HttpServletResponse resp)
              String myfile="";
              try
                   //Correct the file name;
                   String p_filename = javaFileParser(fileName);
                   File newDir = new File(Directory);
                   //Check if the directory does not exists!
                   if(!newDir.exists()) { //If it doesn't..
                        //Create the directory
                        newDir.mkdir();
                   String complete_path = Directory + p_filename;
                   File myFile=new File(complete_path);
                   //Check if a filename like this already exists!
                   if(myFile.exists()) {
                        //If it does..
                        //delete the current file residing into the directory
                        myFile.delete();
                   //Write the file (START)
                   FileOutputStream fos = new FileOutputStream(myFile);
                   BufferedOutputStream bos = new BufferedOutputStream(fos);
                   BufferedInputStream bis = new BufferedInputStream(input);
                   int aByte;
                   while ((aByte = bis.read()) != -1)
                   bos.write(aByte);
                   bos.flush();
                   bos.close();
                   bis.close();
                   //(END)
              catch (Exception x)
                   System.out.println("Error : " + x);
         private void pushFile(String fileName,InputStream input, HttpServletResponse resp)
              try
                   //Download the file to the Client's machine
                   ServletOutputStream stream = resp.getOutputStream();
                   resp.setContentType("application/octet-stream");
                   resp.setHeader("Content-Disposition","attachment;filename="+fileName.trim()+";");
                   //BufferedInputStream fif = new BufferedInputStream(new FileInputStream(complete_path));
                   BufferedInputStream fif = new BufferedInputStream(input);
                   int data;
                   while((data = fif.read()) != -1)
                   stream.write(data);
                   stream.flush();
                   fif.close();
                   stream.close();
              catch (Exception x)
                   System.out.println("Error : " + x);
         private String javaFileParser(String filename)
              //System.out.println("In EmailObject javaFileParser");
              String n_filename="";
              //Check if the file starts with '=?iso8859'
              //If it does, it will need parsing
              if(filename.startsWith("=?iso")) {
                   n_filename = filename.substring(15,filename.lastIndexOf("?"));
              } else
                   n_filename = filename;
              return n_filename;
    I suggest don't use JavaMail.. It has BUGS on some other email type. If not in POP3 then in IMAP.. Specialy when it receives "Enriched" contents types. Better yet don't use Java. It has lots of Bugs.

  • Send multiple email attachments using FM SO_NEW_DOCUMENT_ATT_SEND_API1.How?

    Hi All,
    I have a requirement to send email to an external ID for which I am using FM SO_NEW_DOCUMENT_ATT_SEND_API1.Can anyone give a sample code to send multiple excel attachments using this function module.
    Points would be rewarded.
    Thanks
    Archana.

    Check the Thread,,
    Re: more than 1 attachements/sheets in SO_DOCUMENT_SEND_API1

  • Auto saving email attachments using date email received as the name of the attachment file

    I would like to be able to batch save hundreds of email attachments in my inbox to a specified folder and use the date and time email was received as the name of the file.  i found sample script that would give it timestamp but would prefer date and time of receipt.  any help would be greatly appreciated.
    thanks.

    I found the below script online but it does not seem to be naming correctly.  it appears that the month always defaults to 12.  perhaps somehow could suggest a fix?
    set theAttachmentPath to (path to desktop) as text
    tell application "Mail"
              set a to selection
    end tell
    repeat with s in a
              tell application "Mail"
                        set current_date to date received of s
                        set CurrentSender to sender of s
              end tell
              set current_date to AppleScriptDateToString(current_date)
              tell application "Mail" to set Attached to mail attachments of s
              repeat with ThisAttach in Attached
                        tell application "Mail" to set FileName to name of ThisAttach
                        if FileName ends with ".pdf" then
                                  set FileName to current_date & " from " & CurrentSender & ".pdf" as text
                                  set FileName to checknamewith_pdfsuffix(FileName, theAttachmentPath, false)
                                  tell application "Mail" to save ThisAttach in theAttachmentPath & (FileName)
                        end if
              end repeat
    end repeat
    on AppleScriptDateToString(a)
              set b to current date
              set monthnames to {}
              repeat with i from 1 to 12
                        set month of b to i
                        set monthnames to monthnames & {(month of b) as text}
              end repeat
              set Y to (year of b)
              set M to 0
              repeat with t in monthnames
                        set M to M + 1
                        if t as text = (month of b) as text then
                                  exit repeat
                        end if
              end repeat
              set M to Twodigits(M)
              set D to Twodigits(day of b)
              set hh to Twodigits(hours of b)
              set mm to (minutes of b)
              set ss to Twodigits(seconds of b)
              return Y & "-" & M & "-" & D as text
    end AppleScriptDateToString
    on Twodigits(a)
              return (characters -2 through -1 of (("0" & a) as text)) as text
    end Twodigits
    on checknamewith_pdfsuffix(n, D, looped)
              tell application "Finder"
                        set thefiles to name of every item of (D as alias)
              end tell
              if thefiles contains n then
                        if looped = false then
                                  set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text
      checknamewith_pdfsuffix(n, D, true)
                        else
                                  set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)
                                  set tmpcount to (count of characters of (tmp as text)) + 5
                                  set tmp to tmp + 1
                                  set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text
      checknamewith_pdfsuffix(n, D, true)
                        end if
              else
                        return n
              end if
    end checknamewith_pdfsuffix

  • IPad will not open email attachments using webmail ?

    Hi We own a iPad 3, OS5.1.1 ( the iPad belongs to my wife ) therefore she has her own account set up using the iPad's email programme ( I do not have my email account on this iPad as we want to keep our accounts seperate)  When I login to my email account using my webmail I can not open any attachement wheather it be pdf.doc,txt ext etc ? when I select the document ( attachment ) nothing happens - if my wife has any pdf's attached to her emails using the iPad's email programme they open without any problems ? I have spoken to my email provider as a webmail programme should be able to open attachments connected with an email - but they are not at all helpful they are suggesting that the problem is with the iPad which I am not at all convinced by unless I am advised other wise by anybody with a technical experience of this problem. We have 3rd party apps such as PDF Reader and also iBooks which can read ePub files - can any body help with this - I am not talking about downloading files here, I am simply talking about the capacity to just open and read an attachment which I can not do with our iPad - we have plenty of memory and drive space, therefore I think it is a bug which might be due to a combination of the webmail programme and the iPad not working with each other - or simply something that is not apparent to me Any help would be much appreciated Many Thanks Mavis

    I had the same problem.
    A colleage sent an email from an ipad with a pdf attachment (via FileApp Pro) and while the email arrived OK and the Inbox shows an attachment there is nowhere to click and open the document from.
    The name of the pdf is listed in the detail of the message but there is no icon within the message to open it with. 
    The first page of the pdf file was shown within the message too.
    The trick was to click and hold somewhere within the first page (displayed in the email).
    This prompts the "Open in ..." popup from which you can open your preferred pdf reader to see the whole document.
    Hope this helps.

  • How to attach a file to an email without using JavaMail

    hi everyone!
    I'm trying to develope a program wich has to send email messages with attached files. Specifications say that I can't use JavaMail. So I'm trying to use SMTP. It's a very simple protocol, but I haven't found how to send attached files.
    Any suggestion or source code? Thanx Very much!!!

    you will need to add a mime body to the data as done in the example message (i found it somewhere on teh internet so don't blame me for erors in it ;) )
    MAIL FROM:<[email protected]>
    RCPT TO:<[email protected]>
    DATA
    Mime-version: 1.0
    Content-Type: multipart/mixed; boundary=OpenVMS/MIME.572522828.951855
    Content-Transfer-Encoding: 7bit
    Message-ID: <572522828.0@>
    --OpenVMS/MIME.572522828.951855736
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline
    We have modified this to send with SFF for SMTP - TCPIP
    Services for OpenVMS.
    --OpenVMS/MIME.572522828.951855736
    for info about how to use mime look at the RFC of mime (just do a google search)
    Robert

  • EMail Attachments using PDF file

    Hi guys
    I have developed an application using Oracle 8i and forms 6i. There is a report developed in 6i repors and saved as PDF format. this file I have to send as attachemnts to the employees.
    Is there any way to send PDF file as attachemnts using forms 6i.
    REgards
    Linga Murthy Mudigonda

    The easiest way (and OS independent, so you don't need Outlook or blat or something like that) is to send the email and attachment from the database. Package utl_smtp won't let you do that, but with Java mail you can. So, after you generated your report, you can mail it using Java mail.
    Everything is described very clearly in note 120994.1 on Metalink (How to Send E-mail With Attachments from PL/SQL Using Java Stored Procedures).

  • Emailing attachments using utl_smtp

    Hi,
    How can one use UTL_SMTP to send a file generated by email as an attachment. I created a MS Excel Spreadsheet on an apps server. I would like to send it as an attachment to recipients.
    Oneway is to use the uuencode in UNIX script.
    But I wanted it to be sent using UTL_SMTP. Could someone please suggest a right direction?
    Thanks
    uds

    Hi Billy,
    Thanks for the updates. My question is how to send a file that is already created as an attachment using UTL_SMTP.
    It is like a truck delivering cargo. It does not make the cargo. In other words, it does construct a completed e-mail for your.
    The file (cargo) is created using UTL_FILE in the apps server. Now I want to use UTL_SMTP to send an email to a list of recipients with this file as an attachment.
    The header that includes data like the e-mail subject, the type of mail and so on. Followed by the body that contains the actual e-mail contents, which includes any attachments
    That is the isuue I am confronting. How do I attach the file already created? Here is the snippet of my code that formulates the body of the email.
    UTL_SMTP.helo (srvr_conn, p_server);
    UTL_SMTP.mail (srvr_conn, p_sender);
    UTL_SMTP.rcpt (srvr_conn, p_recipient);
    UTL_SMTP.open_data (srvr_conn);
    UTL_SMTP.write_data (srvr_conn,
    'Content-Type: text/html' || UTL_TCP.crlf
    UTL_SMTP.write_data (srvr_conn,
    'Subject : Transaction types available'
    || UTL_TCP.crlf
    UTL_SMTP.write_data (srvr_conn, 'To : ' || p_recipient || UTL_TCP.crlf);
    UTL_SMTP.write_data
    (srvr_conn,
    '<br> <html> <body> <table border="1" bordercolor="black">
    <tr>
    <th><font SIZE="2"><b>Trx ID</b></FONT></th>
    <th><font SIZE="2"><b>Trx Code</b></FONT></th>
    </tr>'
    FOR rec IN c1
    LOOP
    UTL_SMTP.write_data (srvr_conn,
    '<tr>
    <td><font SIZE="1">'|| rec.trx_id|| '</FONT></td>
    <td><font SIZE="1">'|| rec.trx_code|| '</FONT></td>
    </tr>'
    END LOOP;
    UTL_SMTP.write_data (srvr_conn, '<br></table></p></body> </html>');
    UTL_SMTP.close_data (srvr_conn);
    UTL_SMTP.quit (srvr_conn);
    Now, how do I ask it to pick the file from server and attach it to the email before "quitting SMTP"? Firstly, can I do that? If yes, can you please suggest me the means how to do it? Your help is much appreciated.
    Thanks
    uds
    PS: c1 is a cursor stmnt; p_server, p_sender, p_recipient are derived from flex values and srvr_conn is type UTL_SMTP.connection

  • Sending email attachments using unix shell script

    hi
    I want to send report generated my spooled file as attachment using unix shell script.
    Can somebody help me out ?
    many thanks

    thanks a tonn it worked.
    but i have another issue is it possible to add names in CC also ?
    Also here is my code which spools the output of SP to a txt file. the File name is generated dynamically.
    as shown below:
    I need to send this generated file as attachement.
    how do I do this? Here the shell script
    =========================================================
    #!/bin/sh
    ORA_USER=scott
    ORA_PWD=tiger
    #Get the input parameter
    if [ ! "$1" ]; then
    STR="NULL"
    else
    STR="'"$1"'"
    fi
    #echo "exec pkg1($STR);"
    #Connecting to oracle
    sqlplus -s <<EOF
    $ORA_USER/$[email protected]
    ---sql plus enviornment settings
    set linesize 160
    set pagesize 60
    set serveroutput on size 1000000 for wra
    set feedback off
    set termout off
    column dcol new_value mydate noprint
    select to_char(sysdate,'YYYYMMDDHH24MISS') dcol from dual;
    spool &mydate.report.txt
    exec pkg1($STR);
    spool off
    EOF
    exit
    =========================================================
    the file name will take sysdate as name so that every time a new file will be generated.
    this file I need to send as attachment.
    null

  • Send email attachments using Java through Outlook Express

    Hi
    Can anyone suggest how we can interface Outlook Express with java in
    order to send email?
    I want to add 'Email Friend' link in my project, on clicking on this
    link Outlook Express should open with a specified file attached.
    I searched on net also, but I am getting only JOC everywhere which is
    not freeware.
    Please suggest me on the same that how it can be done?
    Thanks
    Ashi

    You can send files to Outlook Express using following:
    using a windows exe runmenu. exe
           File file = new File("./lib/runmenu.exe");
            try
                String commandForNotesMail =
                    file.getCanonicalPath() +
                    " \"/exec: send to\\mail recipient\" " + filename;
                System.out.println("Cononical Path :" + commandForNotesMail);
                Runtime.getRuntime()
                    .exec(commandForNotesMail);
            catch (IOException e)
                e.printStackTrace();
            return true;
        }

  • URGENT : Multiple Attachments using JavaMail

    Hello ,
    I'm trying to send multiple attachments to a single mailid. I have 3 text boxes in my JSP page which holds the file name that is selected . in the next page i retrieving the values of those filenames and sending it as attachment .
    But when i do so , i'm getting NullPointeException when one of 2 file is choose . but when i choose 3 files to send , it is working fine . Can any one help pls,
    Here is the code
    public class Attachservlet extends HttpServlet{
         public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
         String host="172.30.1.35";
         String full[]=new String[3];
         String part[]=new String[3];
         String fname[]=new String[3];
         String pname[]=new String[3];
         String ss[]=new String[3];
         String name[]=new String[3],conc="";
         int j,jj;
         String sender_email=req.getParameter("senderemail");
         String sender_name=req.getParameter("sendername");
         String receiver_email=req.getParameter("receiveremail");
         String receiver_name=req.getParameter("receivername");
         String sent_message=req.getParameter("area");
         PrintWriter out=res.getWriter();
         Properties props=System.getProperties();
         props.put("mail.smtp.host",host);
         Session session=Session.getDefaultInstance(props,null);
         MimeMessage message=new MimeMessage(session);
         try{
         for ( jj=0;jj<3;jj++){
         j=jj+1;
         name[jj]="filename"+j;
         pname[jj]="pname"+j;
         ss[jj]=req.getParameter(name[jj]);
         part[jj]=req.getParameter(pname[jj]);
         if(ss[jj].length()!=0){
         System.out.println("values is "+ss[jj] +"\n"+part[jj]);
         System.out.println("values is "+ss[jj] +"\n"+part[jj]);
         conc=conc+ss[jj]+",";
         System.out.println(conc);     
         message.setFrom(new InternetAddress(sender_email,"Sumathi"));
         message.addRecipient(Message.RecipientType.TO,new InternetAddress(receiver_email));
         message.setSubject(receiver_name);
         BodyPart bodypart=new MimeBodyPart();
         bodypart.setText(sent_message);
         Multipart multi=new MimeMultipart();
         multi.addBodyPart(bodypart);
         bodypart = new MimeBodyPart();
         DataSource source=new FileDataSource("test.jsp");
         bodypart.setDataHandler(new DataHandler(source));
         bodypart.setFileName(part[jj]);
         multi.addBodyPart(bodypart);
         message.setContent(multi);
         Transport.send(message);
         res.sendRedirect("http://sumathi/Mail/Success.jsp");
         System.out.println("Message Sent");
         }catch(Exception e){
         System.err.println("An Exception has Arrised \t"+e);
         public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
         doPost(req,res);
    Any Help pls ,
    Thanks in Advance !

    OK,
    Although you didn't post the stack trace from your NullPointer, my guess is that it's being thrown at this line:
    if(ss[jj].length()!=0){
    your ss[jj] variable is being assigned the value: req.getParameter(name[jj]); This value is null in the case when you have anything less that 3 parameters in your form.
    You need to check for a null value at this point.

  • Problem with sending large HTML files as attachment using JavaMail 1.2

    Hi dear fellows, i am currently working on posting Emails with attachments using JavaMail 1.2. i succeeded in sending many mimetypes of files as attachments except for .htm and .html files. when large HTML files (say, >100 kB) serve as attachements, the mail is posted on mail server, but not properly posted since only the first small part of the file is writted into mail server but the latter part of the attachment file is missing.
    is that a bug of JavaMail??? are there any fellows encountering similar problem as i did??? any suggestions for me to proceed? hopefully i made myself clear...
    Many thanks in advance,
    Fatty

    i've sort of found the cause for that, it is because when the stream write to the mail server, unfortunately there is a "." in a single line. so the server refuse to take any more inputs.
    so do i have to remove all the "." in the file manually to avoid this disaster? any suggestions??
    Fatty

  • Using attachments with javamail

    Hi
    I wonder if anyone could help me. Is is possible to send an (oracle)blob as an attachment using javamail? How would I go about doing this? Thanks in advance

    You can attach arbitrary binary data to an email sent through javamail. How the recipient interprets that data depends on the mime type and on their email client. I think a mime type of application/octet-stream will result in a binary file for which the only option is saving to disk.
    Below are code snippets from part of a program in which I deal with attachments. They are far from complete, but show all the important method calls.
    import javax.mail.*;
    import javax.mail.internet.*;
    attachment = (NotifyInterface.Attachment)allData.getObject();
    headers = new InternetHeaders();
    headers.addHeader("Content-Type", attachment.getMimeType());
    encodedData = base64Encode(attachment.getData());
    mbpAttachment=new MimeBodyPart(headers, encodedData);
    mbpAttachment.setFileName(attachment.getFileName());
    mbpAttachment.setDisposition(MimeMessage.ATTACHMENT);
    mbpAttachment.setHeader("Content-Transfer-Encoding", "base64");
    byte[] base64Encode(byte[] rawData) throws MessagingException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    OutputStream out = MimeUtility.encode(bout, "base64");
    try {
    out.write(rawData);
    out.close();
    } catch(IOException e) {
    throw (MessagingException)new MessagingException("Error encoding attachment").initCause(e);
    return bout.toByteArray();
    public static class Attachment implements Serializable {
    String fileName;
    String mimeType;
    byte[] data;
    public Attachment(String fileName, byte[] data, String mimeType) {
    this.fileName = fileName;
    this.data = data;
    this.mimeType = mimeType;
    public String getFileName() {
    return fileName;
    public String getMimeType() {
    return mimeType;
    public byte[] getData() {
    return data;
    public String toString() {
    return "Attachment of type "+mimeType;

  • Email attachments Forms 6/Ora 8.1.5.1.0 using Outlook

    Hello everyone...
    I have spent the last few hours researching this, now I'm finally posting because I can't find an answer...
    Is there any way to e-mail an attachment in Outlook 2000 from Forms 6?
    Using the host command I can create an e-mail message in outlook, but I can't attach a file.
    UTL_SMTP : will only e-mail text correct?
    We are using Outlook 2000 - without exchange. But if we need to get exchange we will.
    Thanks for any input at all.
    Lesley.

    1) Yes it is possible to include an attachment in outlook when using OLE to automate it. If you look at the OLE interfaces for Outlook you'll see there is an attachments collection that can be used for this. I did this about 5 years ago and don't have the code any more but it can be done. :-(
    2) You can use JavaMail to do the sending - this does allow attachments - In Forms 9i we have a demo that uses Java on the middle teir to hook into JavaMail and supports attachments as well as plain emails.
    The 9i code could be backported for 6i both Client server or Web Deployed.
    http://otn.oracle.com/sample_code/products/forms/content.html

Maybe you are looking for

  • Do I need an agreement with Apple to sell a textbook created by iBooks Author on iBookstore?

    Hello, I created my .ibooks fortmatted book by iBooks Author. And I would like to sell it on iBookstore. In the past I have published several ePub books on iBookstore. So I have my iTunes connnect account for it. And my question are - Should I have a

  • Application not visible in PDA  after server deployment

    Hi All, I developed an Mi 7.1 application.Deployed  all the sdas in the Mi server using sdoe_upload_archive.I created a device.Assigned all the mobile components to the device .I synchronized the device and it is successful. I can see the service and

  • Issue with Oracle Application Adapter (11g) for SAP

    Hi, I need to call a WSDL file that is generated through Oracle Application Adapter Application Explorer from a BPEL Composite in SOA 11g. The wsdl files are stored under the path $SOA_HOME/soa/thirdparty/ApplicationAdapters/wsdls by default. I'm not

  • SAP Webdispatcher and URL redirect - 3 systems, one webdispatcher

    Good day, I have the following scenario, webdispatcher in the DMZ that redirects to Enterprise Portal internally. There is a role in EP which is setup for webgui to 2 seperate ERP systems. Is it possible to have 3 seperate redirects on the webdispatc

  • EXT Display Format LabVIEW bug

    Up for grab, this easy bug (tested in LV 2012.0f3 (32 bit) on Windows XP) From a clean start, create a new VI, drop a "Power of x" function and create control for all input and output. Set the representation of the controls/indicators to be "Extended