Javax.mail CSV file attachment corrupt?

I'm having some trouble with attaching a file to an outgoing email, it's a CSV file and when it is uploaded/attached to the email, it becomes "corrupt". Excel will still open it but if I open it in notepad the formatting is noticeably messed up. I need it to retain all the correct return carriages and line feeds, which I believe are what are getting mingled. (Another program must read it and this formatting is messing everything up).
Here's the code:
MimeBodyPart messageBodyPart =
                 new MimeBodyPart();
         //fill message
         messageBodyPart.setText(outBoundMessage);
         Multipart multipart = new MimeMultipart();
         multipart.addBodyPart(messageBodyPart);
         if (fileAttachment != null) {
            // Part two is attachment
            MimeBodyPart attachment = new MimeBodyPart();
            attachment.attachFile(fileAttachment);
            attachment.setFileName(fileAttachment.getName());
            attachment.setHeader("type", "text/csv");
            multipart.addBodyPart(attachment);
         // Put parts in message
         message.setContent(multipart);The other parts of the message are being created and attached where necessary. My guess is that it's not transferring in binary? I've never really done this sort of thing so if anyone could lend a hand and show me how to properly attach files so they don't get altered in anyway I would greatly appreciate it.

Hi,
I am sending csv file as an attachment by using below code
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class AttchmtMail
    String finaldt;
        public  void mailAtchmt(String fname,String dt) {
            String   to="[email protected]";
           String from = "[email protected]";
          String to2="[email protected]";
             String host = "xxx.xx.xxx.xxx";
            // Create properties, get Session
            Properties props = new Properties();
            // If using static Transport.send(),
            // need to specify which host to send it to
            props.put("mail.smtp.host", host);
            // To see what is going on behind the scene
            props.put("mail.debug", "true");
            Session session = Session.getInstance(props);
            try {
                // Instantiatee a message
                Transport bus = session.getTransport("smtp");
                bus.connect();
                Message msg = new MimeMessage(session);
                //Set message attributes
                msg.setFrom(new InternetAddress(from));
                InternetAddress[] address = {new InternetAddress(to),new InternetAddress(to2)};
                msg.setRecipients(Message.RecipientType.TO, address);
                msg.setSubject("New OU's on "+dt+".");
                msg.setSentDate(new Date());
               // String filename= "C:/Feeds/"+finaldt+"/"+files;
String file1= fname;
File f1=new File(file1);
if(f1.exists())
setFileAsAttachment(msg, file1);
else
//setFileAsAttachment(msg,"","",info);
msg.saveChanges();
bus.sendMessage(msg, address);
bus.close();
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
public void setFileAsAttachment(Message msg, String filename)
throws MessagingException {
// Create and fill first part
MimeBodyPart p1 = new MimeBodyPart();
p1.setText("Dear ,\n\nPlease check the attachment " );
// Create second part
MimeBodyPart p2 = new MimeBodyPart();
// Put a file in the second part
if(!filename.equals(""))
FileDataSource fds = new FileDataSource(filename);
p2.setDataHandler(new DataHandler(fds));
p2.setFileName(fds.getName());
// Create the Multipart. Add BodyParts to it.
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
if(!filename.equals(""))
mp.addBodyPart(p2);
} // Set Multipart as the message's content
msg.setContent(mp);
}//End of class
Madhu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • SOAP Axis sender with CSV file attachment

    Hi Experts,
    I have a requirement where I receive a CSV file attachment from a Web Service post ( i.e a SOAP sender with attachment). I decided to use SOAP with Servlet(Axis) protocol, since standard SOAP sender does not allow modules to be used.
    I am able to test this interface through SOAPUI with attachment to the point where I can get the attachment payload as my main payload in IE, but it fails in mapping since CSV needs to be converted to XML. I have following queries for proceeding ahead with this scenario:
    1. How do I convert the CSV attachment to XML inorder for mapping to be used in IE. Is there a standard axis handler available for this ???? Also where should this handler be called in the sequence of Axis modules ???
    2. Can I use MessageTransformationBean for converting plain to XML ??? If yes where should this module be called in the sequence of Axis modules. I tried using this module between the CallSapAdapter and the first AdapterBean but it returns exception in SOAPUI saying " Messaging exception: No Main"
    3. Is there a blog available which illustrates about using additional modules/handlers in Axis. I have had a look at the FAQ note of Axis but it just gives the overview.
    Thanks.
    Siddhesh S.Tawate

    Solved :).
    1     AF_Adapters/axis/HandlerBean                     Local Enterprise Bean                              xireq
    2     AF_Adapters/axis/AFAdapterBean                     Local Enterprise Bean                              afreq
    3     localejbs/AF_Modules/MessageTransformBean    Local Enterprise Bean                     Plain2XML
    4     CallSapAdapter                                          Local Enterprise Bean                              sap
    5     AF_Adapters/axis/AFAdapterBean                    Local Enterprise Bean                             afresp
    6     AF_Adapters/axis/HandlerBean                    Local Enterprise Bean                             xires
    Above sequence worked. I guess I was missing some parameter in content conversion earlier.
    Thanks.

  • Sender "Mail" adapter - CSV file attachment

    Hi there
    I'm looking for some help in configuring a sender mail adapter that receives ".csv" files. I did read some blogs that mention using the "PayloadSwapBean" module to read the mail attachment instead of the mail content. My problem is to now convert the ".csv" file into a message. Is there a module that I can use ( is it the "MessageTransfomBean" ) and how. Any help would be appreciated.
    Thanks
    Salil

    Hi Salil,
    If you want to send a mail with a body and attachments, the message sender HAS to provide an XI message with attachments. I doubt a CSV file does justice.
    As Renjith said you need to convert CSV to XmL.
    A short description about the Standard Modules:
    MessageTransformationBean is a standard module used to apply the XSLT mapping to the adapter module by using <i>Transform.class</i> ( This xslt mapping is done to create a mail package, Dont confuse with the actual mapping in your case this is NOT for converting csv to xml).
    Also this module can be used to change the name and type of payloads by using <i>Transform.contentType</i>, <i>Transform.contentDisposition</i>, <i>Transform.contentDescription</i>.
    PayloadSwapbean is a standard module for replacing payloads with other payloads (SWAP)
    If you want to give each attachment a certain name use Parameters, <i>swap.keyname</i> for name of the payload and <i>swap.keyvalue</i>.
    I Hope the use of standard modules is understood.

  • CSV File attachment in Receiver Mail Adapter

    Hi Experts ,
                                   mine is a proxy to mail scenario  Information from proxy needs to be converted to CSV file and to be send across in the form of attachment to multiple recievers.
       I would request best suggestions from experts.
    Regards,
    Arnab .

    Hi,
    first approach is,
       1. in cilent proxy report to call  'GUI_UPLOAD' function module ,    in  exporting, filetype =  'txt', filename.
    second approach is,
       2. you can you message transformation bean in you mail receiver communication channel.
    http://help.sap.com/saphelp_nw04/helpdata/en/57/0b2c4142aef623e10000000a155106/frameset.htm
    you want to send multiple receivers ,
    3. In the Receiver Determination, you need to select " Extended" in the Type of Receeiver determination.
    http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3343.
    regards,
    ganesh.

  • Issue in CSV file attachment.

    Hi All,
             I am using the FM : SO_DOCUMENT_SEND_API1 for sending mails in CSV format. This CSV file contains some chinese scripts. But when I open the attachment I can see some junk characters instead of that. My SAP version is 4.6c
    I searched in all the forums and found these 2 solutions
    1. OSS note 633265 .
    2. Changed the characters set into simplified and traditional chinese.
    Both didnt helped.
    Suggestions are welcome.
    Regards,
      Dinesh.

    Hi Dinesh,
    again: Never use FM : SO_DOCUMENT_SEND_API1 . Go for CL_BCS. Check programs
    BCS_EXAMPLE_5
    BCS_EXAMPLE_6
    BCS_EXAMPLE_7
    BCS_EXAMPLE_8
    Regards,
    Clemens

  • Mail to File: Attachment is not getting picked

    Dears,
    I have configured a Mail to File Scenario: Where PI will read email and pick the first attachment (.PDF File) and place it on File Server, however some times it is not picking the attachment and not placing it on File server.
    Case1: In this case, it is working perfectly... the PDF file 145-2015.pdf is placing on file server
    Case2: In this case, the attachment is not placing on File server. DECORP F221.pdf file not placing on File server
    Your help need to solve this issue...
    Thanks-
    Rams

    Hello,
    I have identified that 'Content-Description' is not populating in the un-successful case because on File Receiver Adapter, i have used 'Content-Description' for the File Name as shown on below screen shot...
    However i need to identify why the 'Content-Description' is missing in some cases...
    This is the reason the attachment is unable to place it on File System...
    Could any one of help me to identify the root cause?
    Thanks-
    Rams

  • Setting required to process incomming Email with CSV file attached

    Dear all,
    We are having a scenario where in the supplier receives a PO confirmation CSV file from the download center as an Email attachment. The supplier updates the file by confirming PO's and replies back. The CSV file needs to update the confirmed PO's in SNC.
    The SO50 settings are in place but still we are not able to receive the Email back in SNC. Any suggestion on what settings we need in SNC to receive and process the CSV file?
    thanks,
    mahehs

    Hi,
    You can use the upload center to process the changed data. Isnt that helpful?
    Best Regards,
    Harsha Gatt

  • Mail and File attachement

    Hello,
    I'm new in developping in Java Server and I need to write a class who can send a mail with one file attachement. I don't now how to do this thing ?
    Thank you for your help.

    Try the tutorial
    http://developer.java.sun.com/developer/onlineTraining/JavaMail/

  • Gmail is not sending mail with files attached

    hey, apple mail serice is sending mail but not sending mail with files atteched.
    Any help?

    Hmm. Looking at the Apple UK support site, it shows a yellow dot for .Mac mail, but says the issue is with incoming mail:
    http://www.apple.com/uk/support/dotmac/
    Not sure if that has anything to do with it or if there are other issues.
    There's also some info at:
    http://www.apple.com/uk/support/dotmac/mail/
    Interestingly enough, they suggest using your ISP's SMTP server for outgoing mail:
    http://docs.info.apple.com/article.html?path=Dotmac/Mail/en/mac14.html
    Have you tried that? You should still be able to send as your .Mac email, but have it sent through there instead.

  • Can't send mails with file attachment

    I can't send any mails from my iphone 3G with file attachments.
    If I try to send a picture I have taken with the iphone the mail just won't go out. It says 3 mails not send at the bottom of the mail app.
    Normal mails work fine.
    Any ideas how to fix this?

    I access two email accounts with the iPhone's Mail client and I've never experienced the same.
    If no change after an iPhone reset, which is done by pressing and holding the home button and the sleep/wake or on/off button simultaneously until you see the Apple logo and then release - ignoring the slide to turn off prompt when doing so, try deleting and recreating the accounts on your iPhone.

  • How can I email using UTL_SMTP with a csv file as an attachment?

    Dear All,
    It would be great if someone could help me. I am trying to use UTL_SMTP to email with a csv file as attachment. I do get an email with a message but no attachment arrives with it.
    In fact the code used for attaching the csv file gets appended in the message body in the email.
    CREATE OR REPLACE PROCEDURE test_mail
    AS
    SENDER constant VARCHAR2(80) := '[email protected]';
    MAILHOST constant VARCHAR2(80) := 'mailhost.xxxx.ac.uk';
    mail_conn utl_smtp.connection;
    lv_rcpt VARCHAR2(80);
    lv_mesg VARCHAR2(9900);
    lv_subject VARCHAR2(80) := 'First Test Mail';
    lv_brk VARCHAR2(2) := CHR(13)||CHR(10);
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25) ;
    utl_smtp.helo(mail_conn, MAILHOST) ;
    dbms_output.put_line('Sending Email to : ' ||lv_brk||'Suhas Mitra' ) ;
    lv_mesg := 'Date: '||TO_CHAR(sysdate,'dd Mon yy hh24:mi:ss')||lv_brk||
    'From: <'||SENDER||'>'||lv_brk||
    'Subject: '||lv_subject||lv_brk||
    'To: '||'[email protected]'||lv_brk||
    'MIME-Version: 1.0'||lv_brk||
    'Content-type:text/html;charset=iso-8859-1'||lv_brk||
    ' boundary="-----SECBOUND"'||
    ''||lv_brk||
    '-------SECBOUND'||
    'Some Message'
              || lv_brk ||
    '-------SECBOUND'||
              'Content-Type: text/plain;'|| lv_brk ||
              ' name="xxxx.csv"'|| lv_brk ||
              'Content-Transfer_Encoding: 8bit'|| lv_brk ||
              'Content-Disposition: attachment;'|| lv_brk ||
              ' filename="xxxx.csv"'|| lv_brk ||
              lv_brk ||
    'CSV,file,attachement'|| lv_brk ||     -- Content of attachment
    lv_brk||
    '-------SECBOUND' ;
    dbms_output.put_line('lv_mesg : ' || lv_mesg) ;
    utl_smtp.mail(mail_conn, SENDER) ;
    lv_rcpt := '[email protected]';
    utl_smtp.rcpt(mail_conn, lv_rcpt) ;
    utl_smtp.data(mail_conn, lv_mesg) ;
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    NULL ;
    WHEN OTHERS THEN
    dbms_output.put_line('Error Code : ' || SQLCODE) ;
    dbms_output.put_line('Error Message : ' || SQLERRM) ;
    utl_smtp.quit(mail_conn) ;
    END;

    LKBrwn_DBA wrote:
    Use UTL_MAIL instead.That package is an utter disappointment - and an excellent example IMO of how not to design an application programming interface. Even the source code is shoddy.. I mean, having to resort to a GOTO statement....!!?? The person(s) who wrote that package are sorely lacking in even the most basic of programming skills if structured programming is ignored and a spaghetti command used instead.
    No wonder the public interface of that code is equally shabby and thoughtless... The mail demo code posted by Oracle was better written than this "+package+" they now have bundled as the official Mail API.
    I dunno.. if I was in product management there would have been hell to pay over pushing cr@p like that to customers.

  • CSV file as an attachment is not in the recognizable format

    Hi All,
    I have a requirement to send a csv file as an e-mail attachment. For this, I am collecting the required data into the final internal table and converted this final internal table data into CSV format and then sending this in the mail as csv file attachment using the functiona module 'SO_NEW_DOCUMENT_ATT_SEND_API1'. Program is working fine and mail is coming to receiver's inbox.
    Well.. Now the problem is, I am getting the message while opening the csv file as "The file is not in a recognizable format." and if we say OK... then it is opening. Now how can we avoid coming of this message while opening the file.
    Please advice.
    Thanks a lot in advance.
    Regards
    Ramesh.

    These are all the Object types which are allowed in the attachement format.. try changing to any of the formats..
    ALI   ABAP list document
    ARC   Archive object (image)
    BCS   External Document Storage
    BIN   Binary document
    DLI   Distribution list
    EXT   PC document
    FOL   Folder
    GRA   SAP Business Graphics
    OBJ   Business object
    OFO   Object folder
    OTF   OTF document
    R3I   IDoc
    RAW   SAP editor document
    SCR   SAPscript document
    URL   Link to Internet/Intranet
    WIM   Work item
    XXL   Document for list viewer

  • Can't open a pdf file attachement to e-mail

    I canot open an e-mail pdf file attachment..I get a message
    You have chosen to open Invoice---pdf
    which is: Firefox HTML Document (479kB)
    What should Thunderbird do with this file?
    Open with Firefox (default)
    I do all of the above but nothing happens and I keep getting the same message over andf over again??
    Please advise what I should do
    Thanksd

    Thanks. I disabled Protected Mode, and I was able to open the pdf attachment. Just to make sure, I enabled it and then disabled it again, and when I tried to open the attachment, it did as before – Adobe Reader (Not Responding) and Internal Error message. Tried it several more times, (enable and then disable Protected Mode) and each time, Adobe Reader wouldn’t launch (Not Responding, Internal Error).
    Morris Davidson

  • File attachment in yahoo mail does not appeare in Firefox 4, but IE & other web browsers show correctly.

    Before I install Firefox 4, I have been use Firefox 3.6 and when I was checking my yahoo mail, there was not any problem to view or download file attachment.
    After installing Firefox 4, when I receive a new mail with file attachment, like as video, or document, I can not see the attachment to download it. but with other web browsers like IE, I can see the attachment of the email.

    Hi!
    People using a Trend Micro virus scanner should disable some webmail function. You can find the solution [http://en.kioskea.net/forum/affich-33677-can-t-download-attachments-on-my-yahoo-email here]
    I do not use Trend Micro, but have the same issues. I just found my "AdBlock Plus" add-on was stopping the attachment download. What you should do to see if this is your problem too: disable AdBlock Plus, restart firefox and see if your problem is solved. Now enable AdBlock Plus again and restart Firefox.
    To fix this problem: In Firefox, click on Add-ons, go to AdBlock Plus, go to Options, click on Filters--> reset statistics. Go to your attachment, click on the attachment (it will fail to download of course). Go back to AdBlock Plus and sort the statistics for "Hits". Now you can see which filter is blocking your attachment download. Disable this filter and you problem is solved!
    Regards!

  • Corrupted Mail preferences file

    Dear all,
    My com.apple.mail.plist file got corrupted somehow. My Home/Library/Mail folder looks fine though. What do I have to do to restore everything back to normal? Bear that I don't have a preference file backup. I would <never> think a simple, tiny file could ruin all my e-mail capabilities... For one moment it reminded me of my Windows days...
    Anyway, I'd appreciate your help in this matter.
    Cheers,
    Leonardo

    The Mail.app preference file stores all account information and general Mail.app preferences.
    With the Mail.app quit and using the Finder, go to Home > Library > Mail. Copy the Mail folder and place the copy on the Desktop for backup purposes.
    Using the Finder, go to Home > Library > Preferences > com.apple.mail.plist. Delete the com.apple.mail.plist file and empty the Trash.
    Note: Moving or deleting the com.apple.mail.plist from the Preferences folder will require re-entering all email account information when re-launching Mail.
    The only exception to this is if you have a .Mac account which will be recreated automatically.
    Launch Mail and decline any prompt to import mailboxes. After re-entering all email account information the same as before, the Mail.app should rediscover the existing account named folders and mailboxes at Home > Library > Mail.
    After confirming all mailboxes were successfully rediscovered, you can delete the copy of the Mail folder from the Desktop.

Maybe you are looking for

  • How to fix an ipod shuffle that won't turn on or charge?

    I have an ipod shuffle 4th generation.  Plugged it in but took it out without ejecting.  Now, it won't recognize in itunes and won't charge or turn on.  What can i do to fix this?  I have the latest itunes and I have reset the shuffle several times.

  • Goods Receipt Not Possible for PO with Free Item Checked (Tick Mark)

    Hi Team, We have a PO with one line item where the free item check box is ticked and net price is blank. When we try to make GR with respect to the PO via T Code MB01 we are getting error as " No goods receipt possible for purchase order xxxxxxxxxxx 

  • Cs3 new functions question before buying

    hello there i want to ask, if the problem with the gifs in textfield componennts still exist in cs3 flash professionell. There was this problem if a textfield gets a text from a shared object and have to put a gif instead of a text like " :-) " then

  • Approval for storage location to storage location or plant to plant movemen

    Hi all, Our client's requirement is when goods transfer from the storage location to storage location with movement type 311 or plant to plant with movement type 301, untill & unless the authorised person at the receiving end approves it, the movemen

  • DB Rebuild instructions

    Greetings SLES10.2 ZCM10.3.4 I'm in the process of upgrading and I want to keep my DB as clean as possible going into the upgrade. I've been trying to rebuild the DB. Following Novell Documentation I once had to call Novell and open an SR for them to