Analyze the text file javax.mail.Message

Hello

I have e-mail messages saved to disk in the form of text files and I'd like to load each message as a javax.mail.Message and analyzed. The reason I want to do is that I will be able to use the java mail API and I already have an analysis program that can scan the headers and the body. Is there a possible way to do this?

Thank you

If the emails are saved as EML file, then you can load them as MimeMessage and then easily analyze.

Source InputStream = new FileInputStream (emlFile);
MimeMessage message = new MimeMessage (mailSession, source);

Complete example at http://www.rgagnon.com/javadetails/java-0458.html

Tags: Java

Similar Questions

  • With the help of javax.mail.internet.MimeMessage etc. to create the EML file

    Hello

    I have e-mail messages stored in a MySQL database and their attachments stored in base64 encoded text.  I try to perform a loop over a query and write properly formatted. EML file for each message.  I started from the borrowed code that was used to send messages IMAP, and I had no experience with Java, but I have since worked through some tutorials and I now know how to write and compile a simple class. But I always hurt (a lot!) to instantiate the correct Java objects in common sense and order in ColdFusion.

    Here is what kind of work, with problems, that I will detail below:

    < cfscript >
    clsSession = createObject ("Java", "javax.mail.Session");
    objProperties = createObject ("Java", "java.util.Properties");


    MSG = CreateObject ("Java", "javax.mail.internet.MimeMessage");
    MMP = CreateObject ("Java", "javax.mail.internet.MimeMultipart");
    MBP = CreateObject ("Java", "javax.mail.internet.MimeBodyPart");
    objRecipientType = CreateObject ("Java", "javax.mail.Message$ RecipientType");


    SDS = CreateObject ("Java", "javax.activation.FileDataSource");


    FSO = CreateObject ("Java", "java.io.FileOutputStream");
    OOS = CreateObject ("Java", "java.io.ObjectOutputStream");

    < / cfscript >

    < cfloop query = "getAllMessages" >

    <!-here I also do a 'qGetMsgAtts' query to get all attachments by getAllMessages.msg_id,

    and valueList (qGetMsgAtts.attIndex) to use to create a "msgAttachmentsList"-->

    <! - initialize a MimeMessage object java - >

    < cfscript >
    objProperties.init ();

    (I was actually setting properties here, but never got their and code works without them)

    objSession = clssession.getInstance (objProperties);


    Message
    Msg.init (objSession);
    msg.addFrom (add.parse (getAllMessages.msgFrom, false));
    msg.setReplyTo (add.parse (getAllMessages.msgFrom, false));
    msg.addRecipients (objRecipientType.TO, add.parse (getAllMessages.msgTo, false));

    Etc... no problem by setting the msg properties
    Increment = increment + 1;


    file name
    thisFileName = "#userId #_ #myFun.doCountToken (increment) # .eml"; my function doCountToken (integer) pads simply with zeroes.


    Parts of body of message
    MBP.init ();
    If (not msgIsHTML)

    {
    mbp.setText ("msgBody");
    }
    on the other
    {
    mbp.setContent (msgBody, "text/html");
    }
    mmp.addBodyPart (mbp);
    msg.setContent (mmp);


    If (len (msgAttachmentsList)) / / message has attachments
    try / / TRY TO ATTACH FILES
    {
    {/ / qGetMsgAtts.colnames: msg_id(2), attIndex, fileName, fileMIMEType, fileMacCreator, fileMacType, fileContents}
    writeOutput (' spare part & msgAttachmentsList & "< br / > '");
    for (i = 1; i is listLen (msgAttachmentsList); i ++)
    {

    FDS.init (qGetMsgAtts.filecontents); WORK

    MBP.init ();

    mbp.setDataHandler (dh.init (SDS)); WORK

    mbp.setFileName (qGetMsgAtts.fileName [i]); WORK

    mbp.setContent (qGetMsgAtts.fileContents [i], qGetMsgAtts.fileMIMEType [i]); WORK

    mmp.addBodyPart (mbp);

    }
    msg.setContent (mmp);
    }
    }
    {} catch (everything except)
    writeOutput ("#excpt. # Error type attach content. #excpt. Message # #excpt. ("Retail # < br >");
    }


    aFile = thisFilePath & thisFileName;  PATH AND NAME
    FOS.init (afile); //
    OOS.init (FOS); //


    try / / WRITE THE FILE TO DISK

    {
    msg.writeTo (oos); ONLY WORKS IF MIME TYPE IS text/plain or text/html
    OOS. Flush();
    OOS. Close();
    FOS. Close();
    }
    {} catch (everything except)
    writeOutput ("#excpt. # Error type attach content. #excpt. Message # #excpt. ("Retail # < br >");
    OOS. Flush();
    OOS. Close();
    }

    < / cfscript >

    < / cfloop >

    But who wrote the correct number of files with the correct file names, there are 2 major problems at this stage:

    1. the content of the file on the disk seems to contain all messages. I do not understand why, I do msg.init () at the top of each loop. (The limit of the part also seems to be the same in all parts in each message.)
    2. I get an error like the following for any MIME type as text/plain or text/html:
      javax.activation.UnsupportedDataTypeException error to fix the content. No object DCH MIME type application/pdf no object MPC for the mimetype application/pdf

    I Googled it and I understand that I probably need to use something like
    bads = createObject ("java", "javax.mail.util.ByteArrayDataSource");
    Baos = createObject ("Java", "java.io.ByteArrayOutputStream");

    .. .somewhere in the mix, but all my attempts to instantiate objects have so far failed, usually with the "method not found" or "constructor not found."

    I hope that the explanation is logical. Someone at - it never to write using ColdFusion EML files? I will be eternally grateful for suggestions or extracts.

    Richard

    York U CA

    EDUYork wrote:

    The following code appears to do what I wanted, except that when I opened an EML message exit 1) it is a corruption at the beginning of the headers and at the end of the body, and 2) the attachments does not actually open...

    ...

    myFileOutputStream = fos.init (emlFile); //
    myObjectOutputStream = oos.init (myFileOutputStream); //

    Hi Richard,

    It seems OK except for the part that writes to a file.  You only need a stream of output here, so just using FileOutputStream. I think ObjectOutputStream is most used for serialization and is probably what is causing the strange result here.

    VR;
    {
    emlFile = emlFilePath & thisFileName;
    outStream is CreateObject ("Java", "java.io.FileOutputStream") .init (emlFile);.
    newMessage.writeTo (outStream);
    outStream.flush ();
    outStream.close ();
    }
    catch (everything except)
    {
    writeOutput ("#excpt. # Error type attach content. #excpt. Message # #excpt. Detail #.
    ");

    only close the stream if it exists
    If (IsDefined ("outStream"))
    {
    outStream.close ();
    }
    }

    BTW, Sun is the best reference for javax.email: http://java.sun.com/developer/onlineTraining/JavaMail/index.html . So, have you ever found if there is an easier way to do it?  I wonder if you can store the entire message (header, etc.) without attachments?

  • load the e-mail address variable of the text file anyone?

    I have the code below, attached to a movieclip that I try to use to call for an email address of a text file. The idea is that the text file can be changed by a luddite, and the recipient's email address has changed in the flash file... but I do not too well...!

    The best I've done is undefined e-mail or garbage.

    any help gratefully received. Thank you.

    ___________________________________
    on {(overview)
    this.gotoAndPlay (2);
    }
    on (release) {}
    loadText = function() {}
    loadText = new LoadVars();
    loadText.load ("email.txt");
    loadText.onLoad = function() {}
    emailAddress = this.eAddress;
    }
    }
    submit.onRelease = function() {}
    getURL("mailto:"+emailAddress);
    }
    }
    on {(deployment)
    this.gotoAndPlay (1);

    Do not leave space before and after "=" symbol
    Here's the Simple function loading

  • Download the text file of the site domain

    I need to download a text file to a directory of a domain site.  Text file is saved  What to do next?

    On your PC, right-click on the text file, and then click on copy.

    Connect to the domain (if you don't know how, you will need to get instructions from the domain administrator on how to configure your PC to connect to the domain - specific settings that are required there and they differ by area - and you may need to be configured on the domain and given rights).  Once the installation program I would map a drive to the field to make easier access next time.  Navigate the site of field to the directory where you want the file to exist.  Right-click on the directory and click on paste.

    The file will now have been copied in the domain site directory (assuming you have the appropriate permissions on the domain server to add files in this directory - you will need to talk to the domain so that administrator it it gives you an "access denied" or "you do not have sufficient to perform this task" or a similar error message).

    That's all there is to it.

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • testimonial widget that reads the text file

    Is there someone who makes a testimonial widget that can read a text file? I am considering this is a block for customer testimonials that can read a file of say 50 different clients we wil cut and paste from various places, so that there is always a fresh review illustrated.

    Themes of Muse has some text widgets: one as a ticker-tape driveand displays a (small) number of citations. But none will allow you to modify a file of text outside the Muse of let's say 50 paragraphs and read on the page, one by one, in order.

    There are a lot of scripts to do exactly what you want, like this: alternating Message text box . JavaScriptSource, and many others, just Google: "alternating rotation script of text message". But are you able to manage scripts and HTML codes in Muse ? Maybe some useful script Wizard can cook a place for you or modify an existing one, provide you a text template file and help hair and be implemented in Muse page.

    Don't let them not to edit your output !

    Ask them to help you with a method to ensure within the Muse:

    1. adds a style and script in the header of page (see Page Properties)

    2 Insert the HTML code on the page (under the object menu)

    3 attach the text file on the site (hyperlink, link to the file)

    So, you can change the text file and download all changes with Muse.

    Hope this helps?

  • Load the text file cannot display some letters such as w and?

    I downloaded a flash template that includes a text file used to load the content. I opened the text file and began to make changes to certain texts, so when I discovered the changes I noticed that some letters and characters are not displayed as the letter w and the question mark? and other letetrs.

    I am a newbie to all of this, please help

    Here is an example of the text that I have included in the text file:

    & privacy_title1 = privacy policy
    & privacy_txt1 = what information do we collect?

    We collect information from you when you register on our site, place an order or fill out a form.

    When ordering or registering on our site, if applicable, you may need to enter your: name, e-mail address, phone number or mailing address. You can, however, visit our site anonymously.

    And here is what he sees when I run the flash model:

    example.jpg

    As you can see the w is missing and the point mark and a few other letters.

    Yes, I have an answer to this problem

    (1) select your text layer

    2) go to your properties panel > character

    (3) change the anti-aliasing to "use the device font.

    This should solve your problem

  • How to set the number of e-mail messages that are stored on my iPhone

    How to set the number of e-mail messages that are stored on my iPhone – so when I don't have a network connection I can see a 'large' number of messages in my Inbox etc.

    This is series is not defined in the world

    You must go to settings-> mail, contacts, and calendars and check the settings of your e-mail provider offers in this area

  • Writing data in the text file or excel spreadsheet

    Hello

    I have a silly question to ask questions about the writing of data in a text file or a spreadsheet. I have an example that simulates a sine-swept DAQmx. The output it provides is the (amplitude and phase) frequency response function that is plotted on a graph (see VI) attached. I like to use these data for further analysis by transmitting the data to a text file or a spreadsheet. I've tried a few things, but the thread is broken. I guess I use the sink badly - so I was wondering, can you please advise me on what sink should I use?

    Your help would be very appreciated,

    Thank you very much

    REDA

    The wire is broken, because you cannot connect this type of data to one of these two functions. The data source type is a table 1 d of the clusters, where each cluster contains two tables. The text file write accepts strings, not clusters. Writing on a file action accepts dynamic data, and while you can convert dynamic data tables, there is no built-in mechanism to convert a table 1 d of the clusters of two matrices.

    What you need to do is to convert the data in a format which can be accepted by these functions. Since you want to have a "spreadsheet" file then you should use writing to the spreadsheet file that creates a delimited text file. Since the frequency data would be the same for the plot of the magnitude and phase diagrams, you can have 3 columns: frequency, amplitude, and phase. You can take off the items using Unbundle by name, and then create a table 2D of each element of the cluster. The real question is to know if you want to save the data at each iteration and if you simply add on the file. The attached figure shows write an initial header and then adding just streaming the data.

  • Add data at the end of a specific line in the text file

    Hello

    I'm trying to add data at the end of the last 4 lines of the text file attached with the ' table to add.  4 rows (422.5800 entry), I would add the first entry of the 'Array to add' entry, on the 5th line to add the second entry of the 'Add picture' and so on.  How can I do this?

    Any help will be appreciated.

    Sincerely,.

    hiNi.

    After re-reading your post, I think that's what you really want to start adding after the first 4 rows.

  • Odd number of columns in the text file

    Hello everyone

    From an Excel (.xls) file, I saved (tabs-delimited text) file and open in Labview. The file has only 2 columns (apparently), but my VI says he has 12! I tried to find any character 'lost' in the file but it's all in the first two columns.

    However, if I open the .xls file, save the text file delimited tab, open this tab delimited text file using excel, hit save and then open in my VI, the VI will tell me that the file has only 2 columns. Strange.

    Enclosed please find my VI (I tried two different methods to load the file and got the same results).

    Thank you

    Dan07

    Around this line, you will notice a bunch of tabs:

    240.4926373\t507.1851226\t\t\t\t...

    Edit: I would like to clean up the source, but if you're stuck here is a way to clean:

  • Can all help with VI to get data (HEX) serial number and write in the text file

    Hello I am struggling with this problem for 2 months... They get help from different I thought I solved the problem, but of no use yet I stand on zero

    Problem: I need to get data on USB high speed HEXAGON shaped (coming in hexadecimal and be stored in the text file to the hexadecimal format as each hexadecimal value online different I'll also to attach the file)

    Get us ASCII on series or VISA read but when trying to convert to hex as shown in text file making it slower to deal with code, I know that my VI will have to improve more... I'm waiting for suggestions

    Need urgent help...

    Thanks in advance

    Hi Ali Afzal,.

    I think that the attached example can work for you. If not, then try the solution with sending the data to a parallel running the loop and store it there.

    Mike

  • Playback/record to the text files using HTML5 as a basis for the code

    Hi, I'm new and I did some research and I found a variety of solutions that seemed a little more complicated than I want. I would like someone to direct me to something that could teach me how to do two things.

    (1) read the text files (essentially my difficulty is how to interact with the file system of playbook for reading files and how to save text files with output 2).

    It is not necessary to try and catch.

    Thanks in advance!

    Hello ignites,

    The following thread contains an example of manipulation of text files and also contains a link to another thread by Tim Windsor where he describes working with other file types:

    http://supportforums.BlackBerry.com/T5/Web-and-WebWorks-development/ReadFile-and-data-manipulation/m...

    Let me know if you have any questions.

    Erik Oros

    BlackBerry Development Advisor

  • When the file is saved in windows 7, save the description with the name of the file by the text file

    I need to save files much but don't have time to write the file name and detailed inform instead. When I want to save the file, windows 7 displays the window requires the file name and type. But I need another box that I can describe the detailed information associated file name. This will generate the text file that detailed information with the name of the file.

    Is there a s/w or windows 7 can do that?

    It is not possible to save a file without a name. You must specify a name for the file. In addition, you can add additional information in the comments of the file area. You can open the section "Comments" by going to the properties of the file and go to the Details tab.

  • alignment of the text file column data

    Hi all

    I want to format the output file as shown in need. Suggestions appreciated. I tried with lpad, rpad in the query. Also tried with justify right in the column after A5 format... (A5 size frame right)

    It is part of an important application.

    Please suggest.

    SQL file

    --------

    set verify off
    Set feedback off
    NewPage 0 value
    set pagesize 63
    set linesize 280
    TOPIC ON THE VALUE

    coil c:\test.txt.
    column heading "CTY" A5 format Change_types

    termout off Set

    Select CT of
    tab;

    output in the text file

    CTY
    -----
    N

    Power required:

    CTY
    -----
    N

    (* See space above)
    Oracle 10g
    running sqlplus

    Thank you

    HA!

    Hello

    G2500 wrote:

    Hi all

    I want to format the output file as shown in need. Suggestions appreciated. I tried with lpad, rpad in the query. Also tried with justify right in the column after A5 format... (A5 size frame right)

    It is part of an important application.

    Please suggest.

    SQL file

    --------

    set verify off
    Set feedback off
    NewPage 0 value
    set pagesize 63
    set linesize 280
    TOPIC ON THE VALUE

    coil c:\test.txt.
    column heading "CTY" A5 format Change_types

    termout off Set

    Select CT of
    tab;

    output in the text file

    CTY
    -----
    N

    Power required:

    CTY
    -----
    N

    (* See space above)
    Oracle 10g
    running sqlplus

    Thank you

    HA!

    This sounds like a job for LPAD.  What exactly have you tried?  It is difficult to say what hurts you without knowing what you were doing.

    I don't have a copy of your table, so I'll use the scott.dept table to illustrate:

    SELECT LPAD (dname, 20) department_name

    OF scott.dept

    ;

    Output:

    DEPARTMENT_NAME

    --------------------

    ACCOUNTING

    SEARCH

    SALES

    OPERATIONS

    You want to justify the right title, like this

    DEPARTMENT_NAME

    --------------------

    ACCOUNTING

    SEARCH

    SALES

    OPERATIONS

    ?

    If so, make this SQL * more order

    Department_name RIGHT-JUSTIFIED COLUMN

    before running the query.  COLUMN... JUSTIFICATION applies only to the topic, not the data.

  • I downloaded a creative pack but stops installing the .msi file, no error message.

    Hello.

    I downloaded a creative pack but stops installing the .msi file, no error message.

    Thank you

    to install the creative cloud desktop application, use the file here, download Adobe Creative Cloud apps | CC free trial Adobe

    [moved from the download, installation, commissioning creative cloud download &install]

Maybe you are looking for