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;

Similar Messages

  • How to use gmail with JavaMail

    JavaMail 1.4 is capable of sending and reading messages using gmail.
    All that's required is to properly configure JavaMail. I'll
    illustrate the proper configuration using the demo programs that
    come with JavaMail - msgshow.java and smtpsend.java.
    Let's assume your gmail username is "[email protected]" and your
    password is "passwd".
    To read mail from your gmail Inbox, invoke msgshow as follows:
    java msgshow -D -T pop3s -H pop.gmail.com -U user -P passwdBy reading the msgshow.java source code, you can see how these
    command line arguments are used in the JavaMail API. You should
    first try using msgshow as shown above, and once that's working
    move on to writing and configuring your own program to use gmail.
    To send a message through gmail, invoke smtpsend as follows:
    java -Dmail.smtp.port=587 -Dmail.smtp.starttls.enable=true smtpsend
            -d -M smtp.gmail.com -U user -P passwd -A [email protected](Note that I split the command over two lines for display, but you
    should type it on one line.)
    The smtpsend command will prompt for a subject and message body text.
    End the message body with ^D on UNIX or ^Z on Windows.
    Gmail requires the use of the STARTTLS command, and requires a
    non-standard port, which the smtpsend program doesn't have command
    line options to select so we set them as System properties on the
    java command. The smtpsend.java program uses the System properties
    when creating the JavaMail Session, so the properties set on the
    command line will be available to the JavaMail Session.
    Again, you can read the smtpsend.java source code to see how the
    command line arguments are used in the JavaMail API. There is,
    of course, more than one way to use the JavaMail API to accomplish
    the same goal. This should help you understand the essential
    configuration parameters necessary to use gmail.
    And no, I won't send you an invitation to gmail. Sorry.

    I notice that it's possible to have sticky posts in these forums. See
    http://forum.java.sun.com/forum.jspa?forumID=534
    the Concurrency forum for an example. Posting a link to the FAQ in a sticky post might reduce the number of FAQs asked here by maybe 1%? Or posts like this one might do well as a sticky?

  • Cant use attachments with hotmail, have silverlight as they specified but they said check my browser which is firefox. pls help

    since hotmail updated their facilities. i am unable to send any attachments with my emails. several other people are having the same problem in their forum and they all use a firefox browser on their pc. i have silverlight installed and enabled in internet explorer tools, but windows has suggested i ask my browser supplier if there is anything they know about or how to check settings with firefox.

    See if this helps you:
    http://support.mozilla.com/en-US/kb/Changing+the+e-mail+program+used+by+Firefox

  • Sending Attachments with JavaMail API

    I have an application where I need to develop a simple e-mail servlet where, from an HTML form, clients can enter their return email address and attach a file and send it to me. The jGuru short course said that when trying to send attachments via a servlet, the user must upload the attachment with the encoding type "multipart/form-data". If I remove the "enctype=multipart/form-data" statement, I can successfully send an email without an attachment. But when I add the statement, the servlet fails. Here is the HTML that I have been using, without success:
    <form enctype="multipart/form-data" action="../servlets/TestEmail" method="post">
    From: <input type="text" name="from" value=""><br>
    Subject: <input type="text" name="subject" value=""><br>
    File to Attach: <input type="file" name="filename"><br>
    Message: <textarea name="message"></textarea><br><br>
    <input type="submit" value="Send">
    </form>
    Can anyone show me the error of my ways?
    Many thanks.
    Chris

    Hi,
    You'll need to use the servlet attachment jar from http://www.servlet.com in your webserver library. Check out the site, it'll tell you what to do.
    I've also done an example servlet at http://www.salniere.com/WebTests/ServletMail which you can download and check out.
    good luck
    Kevin

  • Using MAPI with JavaMail

    I want to use MAPI protocol to send mail. Is it possible with java mail API.
    I would appreciate if some body can give me a solution.
    Thanks
    Saikumar

    There are only two JavaMail providers by Sun and are for POP3 and IMAP.
    For MAPI, there is no JavaMail provider, but JIntegra has a product called
    JESP-JavaMail Exchange Service Provider.
    This is JavaMail implementation and is like a provider.
    You can use this provider, which internally makes MAPI calls.

  • Problem Sending attachments with JavaMail API

    Hi,
    I am able to succesfully able to send the attachment but the body message is not going with it. If i dont send the attachment then the email body goes properly. i can't understand what the problem is . please help.
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    import com.sun.mail.smtp.SMTPMessage;
    public class Emailer
         String emailSubject = null;
         String emailBody = null;
        String smtphost = null;
         String ccAddr = null;
         String file = "C:\\trainee\\eclipse_lg.gif";
         Vector vecToAddr = null;
         Vector vecCCAddr = null;
         Address fromAddr = null;
      public Emailer(Hashtable hashConfigParam) throws Exception
            smtphost = (String)hashConfigParam.get("host");
            ccAddr = (String)hashConfigParam.get("ccAddr");
            vecToAddr = new Vector();
            vecCCAddr = new Vector();
      public Boolean setFromAddr(String fromEmailAddr)
              try
                   fromAddr = new InternetAddress (fromEmailAddr);
                   //if(true)
                   //throw new IOException();
              catch (Exception e)
                   return null;
         return new Boolean(true);
      public Boolean setToAddr(String toEmailAddr)
              try
                   for(int j=0; j< vecToAddr.size();j++)
                        if(((String)vecToAddr.get(j)).equals(toEmailAddr))
                             return new Boolean(false);
                   vecToAddr.add(toEmailAddr);
                   //if(true)
                   //throw new IOException();
              catch (Exception e)
                   return null;
                   return new Boolean(true);     
         public Boolean setCCAddr(String ccEmailAddr)
              try
                   for(int j=0; j< vecCCAddr.size();j++)
                        if(((String)vecCCAddr.get(j)).equals(ccEmailAddr) && ((String)vecCCAddr.get(j)).equals(ccAddr))
                             return new Boolean(false);
                   vecCCAddr.add(ccEmailAddr);
                   vecCCAddr.add(ccAddr);
                   //if(true)
                   //throw new IOException();
              catch (Exception e)
                   //System.out.println(e.getClass().getName());
                   return null;
              return new Boolean(true);               
         public Boolean setEmailSubject(String subject)
              try
                   emailSubject = subject;
                   if(emailSubject.equals(null))
                        return new Boolean(false);
                   else
                        return new Boolean(true);
              catch (Exception e)
                   return null;
              //return new Boolean(false);
         public Boolean setEmailBody(String body)
              try
                   emailBody = body;
                   if(emailBody.equals(""))
                        return new Boolean(false);
                   else
                        return new Boolean(true);
              catch (Exception e)
                   return null;
              //return new Boolean(false);
      public void sendEmail()
           try
                Properties eMailConfigProps = null;
                eMailConfigProps = System.getProperties();
                eMailConfigProps.put("mail.smtp.host", smtphost);
                Session session = Session.getInstance(eMailConfigProps, null);
                MimeMessage message = new MimeMessage(session);
                   try
                     message.setFrom(fromAddr);
                      for(int i=0; i< vecToAddr.size(); i++)
                         message.addRecipient(Message.RecipientType.TO,new InternetAddress((String)vecToAddr.get(i)));
                         for(int i=0; i< vecCCAddr.size(); i++)
                          message.addRecipient(Message.RecipientType.CC,new InternetAddress((String)vecCCAddr.get(i)));
                      message.setSubject(emailSubject);
                      //message.setText(emailBody);
                       BodyPart messageBodyPart = new MimeBodyPart();
                        messageBodyPart.setText(emailBody);
                        Multipart multipart = new MimeMultipart();
                        DataSource source = new FileDataSource(file);
                        messageBodyPart.setDataHandler(new DataHandler(source));
                        messageBodyPart.setFileName(file);
                        multipart.addBodyPart(messageBodyPart);
                        message.setContent(multipart);
                        Transport.send(message);
                   catch (SendFailedException ex)
                     ex.printStackTrace();
                   catch (MessagingException ex)
                     System.err.println("Exception. " + ex);
           catch (Exception e)
                System.out.println(e.toString());
    public static void main(String args[])
          Hashtable hash = new Hashtable();
          hash.put("host","213.312.230.211");
          hash.put("ccAddr","[email protected]");
         try
               Emailer objEmailer = new Emailer(hash);
              Boolean fromFlag = objEmailer.setFromAddr("[email protected]");
              String toAddresses = "[email protected]";
              String ccAddresses = "[email protected]";
              Boolean toFlag = objEmailer.setToAddr(toAddresses);
              Boolean ccFlag = objEmailer.setCCAddr(ccAddresses);
              Boolean subjectFlag  = objEmailer.setEmailSubject("Emailer.java");
              Boolean bodyFlag = objEmailer.setEmailBody("blah blah blahblha ");
              if((fromFlag.toString()).equals("true") && (toFlag.toString()).equals("true") && (bodyFlag.toString()).equals("true"))
                   objEmailer.sendEmail();
         catch(AddressException e)
              e.printStackTrace();
         catch(Exception e)
              e.printStackTrace();

    i.e example :
    u can do it in this way
    MimeBodyPart messageBody = new MimeBodyPart();
    messageBody.setText("your message body goes here");
    // attaching file i.e make separate object of body part
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filePath);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(fileName);
    multipart.addBodyPart(messageBody);
    multipart.addBodyPart(messageBodyPart);
    mimemessage.setContent(multipart);
    Transport.send(mimemessage);

  • Using Attachments with Mail

    When I am attaching a JPEG or PDF, the whole picture displays.
    Can this be changed so that just the file is attached??
    Also - I didn't see a section for mail questions, so if this should be posted elsewhere please let me know.
    Thanx,
    FWW

    Whether the file is displayed or not is specific to the email client. The file is always attached.
    The mail sections are specific to the OS that you are using, for example if you are using OS 10.4 you would find it at:
    Apple.com > Support > Discussions > Mac OS X v10.4 Tiger > Mail & Address Book - Tiger

  • Iam unable to send multiple attachments with a mail using JavaMail?

    Hai to all,
    Iam unable to send multiple attachments with a email,see
    iam have succeeded in sending one attachment with a email.
    when iam tring to add two or more attachments to a mail,
    it is giving a Exception like this:
    javax.mail.MessagingException: IOException while sending message;
    nested exception is:
    java.io.IOException: No content
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:577)
    at javax.mail.Transport.send0(Transport.java:151)
    at javax.mail.Transport.send(Transport.java:80)
    at AttachFilesModified.sendMail(AttachFilesModified.java:185)
    at AttachFilesModified.main(AttachFilesModified.java:43)
    this is my code snipnet:
    BodyPart messageBodyPart = new MimeBodyPart();
    Multipart multipart = new MimeMultipart();
    if(body != null)
    messageBodyPart.setText(body);
    multipart.addBodyPart(messageBodyPart);
    /*if(attachments != null)
    for(int i = 0; i < attachments.length; i++)
    String filename="D:\\nagaraju\\apachi\\axis-bin-1_3.zip";
         //String s[]=filename.split("\\");
         //System.out.println(s);     
              //String s1=s[1];
              //String filename1=s[s.length-1];
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filename);
         messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);
    multipart.addBodyPart(messageBodyPart);
         //second file attaching
         /*String filename1="C:\\nagadoc.txt";
         BodyPart messageBodyPart1=new MimeBodyPart();
         DataSource source1=new FileDataSource(filename1);
         messageBodyPart.setDataHandler(new DataHandler(source1));
         messageBodyPart.setFileName(filename1);
         multipart.addBodyPart(messageBodyPart1);
    mess.setContent(multipart);
    Address[] allRecips = mess.getAllRecipients();
    if(toStdOut)
    System.out.println("done.");
    //System.out.println("Sending message (\"" + mess.getSubject().substring(0,10) + "...\") to :");
    System.out.println("Sending message................");
    for(int i = 0; i < allRecips.length; i++)
    System.out.print(allRecips[i] + ";");
    System.out.println("...");
    Transport.send(mess);
    if(toStdOut)
    System.out.println("done.");
    return 0;
    What's wrng with that code snipnet?
    Nagaraju G.

    This works fine with me, try it or compare it if you want.
    public void sendEmail( String from, String to,
    String subject, String body) {
    fMailServerConfig.put("mail.smtp.host", " <<mail server>>");
    Session session = Session.getDefaultInstance( fMailServerConfig, null );
    MimeMessage message = new MimeMessage( session );
    try {
    message.setFrom(new InternetAddress(from));
    message.setRecipient(Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject( subject);
    message.setText( body);
    //Adds Attechment:
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Here are my attachments");
    multipart.addBodyPart(messageBodyPart);
    messageBodyPart = new MimeBodyPart();
    //first attachment
    DataSource source = new FileDataSource("C:\\img1.jpg");
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName("C:\\Telnor1.jpg");
    multipart.addBodyPart(messageBodyPart);
    //Second attachment
    DataSource source2 = new FileDataSource("C:\\img2.jpg");
    messageBodyPart.setDataHandler(new DataHandler(source2));
    messageBodyPart.setFileName("C:\\Telnor2.jpg");
    multipart.addBodyPart(messageBodyPart);
    //etc...
    message.setContent(multipart);
    Transport.send( message );
    }catch (MessagingException e){
    System.err.println("Cant send mail. " + e);
    The error on your code might be:
    BodyPart messageBodyPart1=new MimeBodyPart();
    DataSource source1=new FileDataSource(filename1);
    messageBodyPart.setDataHandler(new DataHandler(source1));
    messageBodyPart.setFileName(filename1);
    multipart.addBodyPart(messageBodyPart1);
    You don't need to create a new BodyPart, and apart from that you'r seting values on "messageBodyPart" but adding "messageBodyPart1" to your multipart :P
    Well see u and have a good one!
    p.s. i know it's a little late from the day you posted, but at least it might help somebody else :D .

  • Sending attachments with emails in Javamail

    I'm trying to send attachments with emails using Javamail. Following is the code through which I'm trying to achieve that. It works as expected on a JRE1.6 environment. But on JRE1.5, the content of the file gets added to the mail body as text.I want the file to be sent as an attachment.
    Any pointers on the observed difference in behavior would be highly appreciated!
    String msgText = mailInfo.getMessage();
            String attachmentFileName = mailInfo.getFileName();
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            mimeBodyPart.setText(msgText);
            // create the second message part
            MimeBodyPart attachmentBodyPart = new MimeBodyPart();
            // attach the file to the message
            FileDataSource fileDataSource = new FileDataSource(attachmentFileName);
            attachmentBodyPart.setFileName(fileDataSource.getName());
            attachmentBodyPart.setDataHandler(new DataHandler(fileDataSource));
            // create the Multipart and add its parts to it
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(mimeBodyPart);
            multipart.addBodyPart(attachmentBodyPart);
            message.setContent(multipart);The email in case of JRE1.5 is as follows
    {color:#0000ff}------=_Part_0_33189144.1233078680250
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Hi...Test Mail
    ------=_Part_0_33189144.1233078680250
    Content-Type: application/octet-stream; name=corba_architecture.pdf
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename=corba_architecture.pdf
    Content-ID: Attachment
    JVBERi0xLjIgDSXi48/TDQogDTggMCBvYmoNPDwNL0xlbmd0aCA5IDAgUg0vRmlsdGVyIC9GbGF0
    ZURlY29kZSANPj4Nc3RyZWFtDQpIiUWPW07DMBBFV+A93E9QlWBP/Kj5awt8USFRbyBKnTQIkshK
    YfvYcQoaybrSzDkzFhCxQgemeWkUyKTXEIeSHMGjZXvHSFBJCpXUpQLcE+NIlbCHFw4pUxeuZQUv
    ueY25gYxk9mKmH9wtwvNpZ99M1+jc2wxXzxweHvf73AP9xGFhaIsTyC3/w6ZDYfxaxoHP8w4jmf/
    ------=_Part_0_33189144.1233078680250-- {color}

    Following is the debug trace obtained on running the program on 1.5.
    +12:45:57,218 INFO [MailerThread] EmailManager:306 - Sending message {toAddress [email protected],+
    +replyTo =null,+
    +cc =null,+
    +message =Hi...Test Mail,+
    +subject =test mail,+
    +contentType =null fileName =C:\docs\cbe\dist computing\A.txt }+
    Loading javamail.default.providers from jar:file:/C:/docs/cbe/lib/mail-1.4.jar!/META-INF/javamail.default.providers
    DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
    DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@77eaf8; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "10.16.68.131", port 25, isSSL false
    +220 mailhost5.vmware.com ESMTP Postfix (mailhost5)+
    DEBUG SMTP: connected to host "10.16.68.131", port: 25
    EHLO sbanerjee
    +250-mailhost5.vmware.com+
    +250-PIPELINING+
    +250-SIZE 26800000+
    +250-VRFY+
    +250-ETRN+
    +250-ENHANCEDSTATUSCODES+
    +250-8BITMIME+
    +250 DSN+
    DEBUG SMTP: Found extension "PIPELINING", arg ""
    DEBUG SMTP: Found extension "SIZE", arg "26800000"
    DEBUG SMTP: Found extension "VRFY", arg ""
    DEBUG SMTP: Found extension "ETRN", arg ""
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: Found extension "DSN", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    +250 2.1.0 Ok+
    RCPT TO:<[email protected]>
    +250 2.1.5 Ok+
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP:   [email protected]
    DATA
    +354 End data with <CR><LF>.<CR><LF>+
    ------=_Part_0_3278348.1233126957281
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Hi...Test Mail
    ------=_Part_0_3278348.1233126957281
    Content-Type: text/plain; charset=us-ascii; name=A.txt
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment; filename=A.txt
    Content-ID: Attachment
    adasdasdd
    ------=_Part_0_3278348.1233126957281--
    +.+
    +250 2.0.0 Ok: queued as 5BE5BDC100+
    +12:45:59,125 INFO [MailerThread] EmailManager:331 - Message {toAddress [email protected],+
    +replyTo =null,+
    +cc =null,+
    +message =Hi...Test Mail,+
    +subject =test mail,+
    +contentType =null fileName =C:\docs\cbe\dist computing\A.txt } sent to the SMTP server successfully+

  • Junk characters display while using multipart with html content in Javamail

    Hi All,
    I have used Java mail API to send mail with attachment. To enable to attachment in mail and to do content formatting i have used multipart and html content type together.
    My web application runs on apache tomcat 5.5 in MAC server. Java version is 1.5.
    The Function which i have used for sending mail with attachment is as follows:
    public void sendmailAttached(String to,String from,String host,boolean debug,String mailContent,String mailSubject,String cc,String attachFiles)
              String mailarray[]=to.split(";");
              Properties props = new Properties();
              //props.put("mail.smtp.port","425");
              props.setProperty("mail.smtp.host", host);
              if (debug) props.setProperty("mail.debug", ""+debug);
              Session session = Session.getInstance(props, null);
              session.setDebug(debug);
              try {
                   Message msg = new MimeMessage(session);
                  msg.setFrom(new InternetAddress(from));
                 javax.mail.internet.InternetAddress[] toAddress=new javax.mail.internet.InternetAddress[mailarray.length];
                 for (int i=0;i<mailarray.length ;i++ )
                                            toAddress=new javax.mail.internet.InternetAddress(mailarray[i]);
              msg.setRecipients(Message.RecipientType.TO, toAddress);
              msg.setSubject(mailSubject);
              try{
                        String ccaray =cc;                    
                        String mailarray1[]=ccaray.split(";");
                        javax.mail.internet.InternetAddress[] CCAddress=new javax.mail.internet.InternetAddress[mailarray1.length];
         for (int i=0;i<mailarray1.length ;i++ )
         CCAddress[i]=new javax.mail.internet.InternetAddress(mailarray1[i]);
              msg.setRecipients(Message.RecipientType.CC,CCAddress);
              }catch(Exception ss)
                        System.out.println("CC mail exception is ====>"+ ss.getMessage());     
              msg.setSentDate(new java.util.Date());
              Multipart multipart = new MimeMultipart("related");
              BodyPart messageBodyPart = new MimeBodyPart();
              messageBodyPart.setContent(mailContent, "text/html");
              multipart.addBodyPart(messageBodyPart);
                   String fileName = attachFiles.substring(attachFiles.lastIndexOf("/")+1,attachFiles.length());
                   if(!fileName.equals(""))
                        messageBodyPart = new MimeBodyPart();
              DataSource source = new FileDataSource(attachFiles);
              messageBodyPart.setDataHandler(new DataHandler(source));
              messageBodyPart.setFileName(fileName);
              multipart.addBodyPart(messageBodyPart);
              msg.setContent(multipart);
              Transport.send( msg );
              catch(MessagingException mex)
                   Exception ex = mex;
                   if (ex instanceof SendFailedException)
                   SendFailedException sfex = (SendFailedException)ex;
    Address[] invalid = sfex.getInvalidAddresses();
    if (invalid != null) {
    if (invalid != null) {
    for (int i = 0; i < invalid.length; i++)
    System.out.println("Invalid Addresss --------> " + invalid[i]);
    try
         Message msg = new MimeMessage(session);
              msg.setFrom(new InternetAddress(from));
              Multipart multipart = new MimeMultipart("related");
         BodyPart messageBodyPart = new MimeBodyPart();      
         messageBodyPart.setContent(mailContent, "text/html");
    multipart.addBodyPart(messageBodyPart);
    Address[] validUnsent = sfex.getValidUnsentAddresses();
    javax.mail.internet.InternetAddress[] toAddress=new javax.mail.internet.InternetAddress[validUnsent.length];                         
    if (validUnsent != null) {
    for (int i = 0; i < validUnsent.length; i++)
    System.out.println("Valid Address ------>"+validUnsent[i]);
    String test = validUnsent[i]+"";
    toAddress[i]=new javax.mail.internet.InternetAddress(test);
    msg.setRecipients(Message.RecipientType.TO, toAddress);
    msg.setSubject(mailSubject);
    String fileName = attachFiles.substring(attachFiles.lastIndexOf("/")+1,attachFiles.length());
                   if(!fileName.equals(""))
                        messageBodyPart = new MimeBodyPart();
              DataSource source = new FileDataSource(attachFiles);
              messageBodyPart.setDataHandler(new DataHandler(source));
              messageBodyPart.setFileName(fileName);
              multipart.addBodyPart(messageBodyPart);
    msg.setContent(multipart);
    Transport.send( msg );
    catch(Exception e)
         System.out.println("Mail Not Send");
              else
                        System.out.println("Mail Server Not Connectd ");
    This code is working properly and i am able to send mail with attachment and html formatted content without any problem. But console of server is filled up with too much junk characters because of which the catalina.out file of tomcat server is becoming fully filled.
    Sample cosnole display with  junk characters are as follows:
    Subject: HBSP - DRUCKER - QC - CH16 - QC  R2 Completed
    MIME-Version: 1.0
    Content-Type: multipart/related;
         boundary="----=_Part_34_15681668.1247471518887"
    ------=_Part_34_15681668.1247471518887
    Content-Type: text/html; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    <b>Hi,</b><br><br>     Chapter CH16 in the project DRUCKER is Completed . <br><br>     <b>Comments :</b> Qc Accepted.<br><br> <b><i>Thanks,<br>ANTONY.</i></b>
    ------=_Part_34_15681668.1247471518887
    Content-Type: application/octet-stream; name=9420317_CH06_p084-119.pdf.zip
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename=9420317_CH06_p084-119.pdf.zip
    UEsDBBQAAAAIAMOz6TqHaQ4BUtXhAGzP8QAZAAAAOTQyMDMxN19DSDA2X3AwODQtMTE5LnBkZsQ7
    CTxUX9tCUpIWEomxpoWZuTN3FmvW7P9skaUajCXGiCHSYiuKFrIvlWStROSvaBEtiIpkK5WlUipa
    ZKl898wYRP/37fve7/e69TjnPuc5z3LOuc95zjP3ym7S1lXAKuL5ZTu7HjTyL8ATiCgMiu6wA6Wi
    gjZy86RSvN12U51QWLQRCguT8ESISED/hcITMWgdFJZIgPAwBm2CwhHQFqAdRySRcWg9lC2KBBNQ
    WAIRZ6+mxk/1dEI48qNYF7+/N9WZHwiCSPyY8QtLQDFLlCf/AhYGgiHyDBwBIs7EETEzcCR4Bg6H
    IZBn4LBE7AwcNBOHJ87EwWQ8aTqOgIWJM3C4mX2JMH6GLiQiHjMDR8bD03BYDBYizcDh8LjpOCyM
    xczAETH4mbgZOmNhmDCDHwE7Qz+IhMNO54eHCKTp/GAcboYuBBJMmi6DSIZxU+lYF7KSJnEMb4qb
    B9WbH1md5sjCROHJMHqTN9VvfPGRcGgzOp2BwhOQMUKZofU9nenIDYF1o22rgtXU1EWGRgsia2vp
    Like this display of junk characters are filling up multiple pages of console file.
    Can any one suggest me how to overcome this problem?
    Many thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    There is no "sendmail" method in the JavaMail API.
    The debug flag is set using the Session.setDebug method, or by setting the Session property "mail.debug".
    If you're using someone else's helper classes with JavaMail, they may provide another way to set it.

  • How to use Java with PL/SQL commands to send an email with attachment

    Apologizes in advance if this is the wrong place to ask the question.
    I need to use Java with PL/SQL commands to send an email with attachment. My java application runs from the command line and does some magic to gather info from an Oracle 11g db. If the DB has sendmail configured, I'd like to send the results of the data gathering as an attachment to the email addresses. I'm not sure how to do this. I've been reading up on on PL/SQL can send email with UTL_SMTP - with attachments. I'm just not sure how to translate that into being triggered by my Java application. Any suggestions or pointers on what I should read would be appreciated.
    Background - I've been programming in Java for 10+ years, but this is my first time using databases. I also have been on these forums for a long time, but lost my profile when it was switched to Oracle.
    Thanks for all help.

    user13726880 wrote:
    The original requirements were put together and given to me, an Oracle newbie. They expected the Java app to use something intrinsic to Oracle and Unix sendmail. To solve my problem, I use a JDBC connection to run some SQL commands. I take that data, format it and send the results by email to the user. By default the requirement is to send it as an HTML attachment using Unix 'sendmail'. So I do that using Runtime exec. I have also added JavaMail functionality as an alternative to sendmail. It works great and as expected.Sounds like a reasonable solution.
    Note however that PL/SQL itself can send email. And PL/SQL can call unix sendmail too.
    However myself I would have done it in java with JavaMail.

  • Problem with Javamail in Red Hat

    Good afternoon.
    I have a problem with javamail in Red Hat.
    When i send a email in windows with my application, works well. But in Red Hat no works.
    Gives the following error:
    Java.lang.ClassCastException .... gnu.mail.handler.TextPlain
    Does anyone know that happens?

    You have much to learn. This is the wrong forum for most of it.
    You should be able to use the package manager in Linux to
    uninstall the Gnu version. Then read this:
    [http://java.sun.com/products/javamail/FAQ.html#install|http://java.sun.com/products/javamail/FAQ.html#install]

  • How can i add a new user and change user'password with javamail?

    how can i add a new user and change user'password from a mailserver with javamail?
    email:[email protected]

    Well user creation and updation is a system property..U need to go through that part...as it depends on the system you are hosting pout your application...
    if it is linux...u have to use some shell programming\
    bye for now let me know if this guides you or if you need some more stuff.
    bye

  • Using Attachments in the Email Adapter

    Hi,
    I'm using an email adapter(Sender - XIPayload) to send message to XI. It was working fine when my mail content was the XML messsage. But now i have to use the content of an attachment file to do the mapping. The attachment is an XML file. I have checked the Keep attachments option and now i can see that the payload contains two sections. One is the mail content and the attachment content. But the mapping fails. How can i specify that the content of the attachment is to be used for mapping? Can somebody give some inputs on how to achieve this?
    Thanks,
    Sandeep

    Hi Sandeep,
    To use attachments in mail adapter, just do the following things:
    -     Set the Keep Attachments indicator.
    -     And you use the PayloadSwapBean module to swap the application payload with one of the attachments.
    Please also go thru the following links:
    http://help.sap.com/saphelp_nw04/helpdata/en/6b/4493404f673028e10000000a1550b0/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/bf37423cf7ab04e10000000a1550b0/content.htm
    Regards,
    abhy

  • Attachments with Webservices -  weblogic 9.2

    Is there a standard stack available for sending attachments with SOAP ? I guess SAAJ 1.2 is partially supported by weblogic. But does this require any changes to WSDL ? SWA and SAW ref implementations as indicated in the JAX-RPC specification is resulting in errors during web service generation from WSDL
    I would like to attach a WAV file to the SOAP request and invoke the web service. I would like to know the best possible way to acheive this in the 9.2 platform. Also let me know whether the service packs have resolved certain issues in this area

    Try using a tool like tcpmon to see the actually HTTP headers and content between IE and WebLogic:
    https://tcpmon.dev.java.net/
    That might give you some clues whether there is something unique in the IE6 request or response.

Maybe you are looking for

  • Can't Stop Auto-Update

    When I connect my BB Bold and startDesktop Manager, it automatically launches into auto-update: "Checking for device application updates...". If I click on "Cancel", it ignores me, but it doesn't hang. It eventually comes up with the message: "Update

  • Defing Website with Xammp

    Hi all, I have a simple question, well hopefully. I installed xamp to preview files locally. i have 5 websites my problem is if website 1 is defined as C:\Program Files\xampp\htdocs\website1\ then it wont preview correctly however if i define it as C

  • LabView 3.1.1 App Build Error

    I have a LabView 3.1.1 App that had been built and was running, and needed a minor change. I made the change and tested it, and it ran fine. I followed the instructions on how to build an application, but after saving all the VIs in a single .llb and

  • Collaboration with captivate

    Hi, We have just set up a team of 5 using Elearning suite 2 and other Cs5 projects Previously we all went our own seperate ways and each person did everything for their project Now we want different people to get images, sound video and put them toge

  • Importing Adobe photshop album files and tags

    I am moving off the PC and onto a new Mac. I am using Adobe Photshop album on my PC and have all my 5 GB of pictures "tagged" with information on who is in it and where it was taken. I will be copying the photos onto the mac and want to use IPHoto. I