JAVAMAIL again...

Hi Developer.
If just go on writing some Applets to send email. Using SDK 1.4.1, NB 3.6, JAVAMail 1.3.1 and SAF 1.0.2 I just cant send mail, because...
...IOException while copying message;
javax.activation.UnsupportedDataTypeException: no object DCH for mime type text/plain
at javax.mail..internet.MimeMessage.<init>(MimeMessage.java:205)
I've searched the archive, finds a lot of entryies, but no help. So I tried it again with these actual source:
public void RTK_sendMail(String body, String subject, String sender, String to, String copy) {
String server = "mail.mydomain.com";
Properties props = new Properties();
props.put("mail.smtp.host", server);
Session session = Session.getDefaultInstance(props, null);
try {
InternetAddress from = new InternetAddress(sender);
InternetAddress[] address = {new InternetAddress(to)};
InternetAddress[] replyto = {new InternetAddress(sender)};
Object objBody = new String(body);
MimeMessage msg = new MimeMessage(session);
// Multipart mp = new MimeMultipart();
// MimeBodyPart mbp = new MimeBodyPart();
msg.setFrom(from);
msg.setReplyTo(replyto);
if (copy != null) {
msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(copy, false));
msg.setSubject(subject, "us-ascii");
msg.setSentDate(new java.util.Date());
msg.setHeader("X-Mailer", "JavaClient/Applet Order-1.000-04/2004");
DataHandler myData = new DataHandler(objBody, "text/plain");
msg.setDataHandler(myData);
com.sun.mail.smtp.SMTPTransport transp = new com.sun.mail.smtp.SMTPTransport(session, new URLName("SMTP", server, -1, "mail", null, null));
com.sun.mail.smtp.SMTPMessage smtpMsg = new com.sun.mail.smtp.SMTPMessage(msg);
transp.connect();
transp.sendMessage(smtpMsg, address);
catch (MessagingException mex) {
mex.printStackTrace();
I've controlled the seqence in the NB-CLASSPATH during compiletime and I think it's ok. The mail server is the same server, where the Applet is at home. I do not now, how I could manipulate the Applet load sequence... If I look into the classloader list, I see javax.mail...., some other classes, my Applet class - but, I can't find any javax.activation class???
So, I that is wrong?

Additional not:
IAfter the initial load of the applet, some javax.mail... class are loaded and no javax.activiation classes. If I press on the button to start send an email, al large number of javax.mail classes and javax.activation classes are loaded in a non-sorted sequence.
Cause that my trouble???

Similar Messages

  • Is there any problem to use multiple threads to send email with JavaMail

    Dear all,
    I am using JavaMail 1.3.2 to send emails with SMTP, it works very well for a long time.
    But one day, I found that the email service hanged and I could never send email again until I restart the tomcat. I found that the reason was a deadlock had been created, the required resource for sending email had not been released.
    I guess the error is due to multiple threads are sending email at the same time. I made a test to create seperate thread for sending each email. After few days, I found this deadlock happened again. So, my question is: Can I use JavaMail with multiple threads? If not, I may need to sychronized all the thread that using JavaMail. I would like to make sure this is the reason for causing the deadlock problem.
    Here is part of my code for using JavaMail:
    transport = session.getTransport("smtp");
    transport.connect(email_host, smtp_user, smtp_pass);
    message.saveChanges();
    transport.sendMessage(message,message.getAllRecipients());
    which is very standard call, and it worked well for a long time.
    Here is part for my thread dump on tomcat:
    (Thread-339)
    - waiting to lock <0x5447c180> (a sun.nio.cs.StandardCharsets)
    (Thread-342)
    - locked <0x5447c180> (a sun.nio.cs.StandardCharsets)
    It seems that these happened after call the method transport.sendMessage() or message.updateChanges()
    , and the underlying implementation may require the JRE StandardCharsets object. But the object had been locked and never be released. So, the sendMessage() or updateChanges() can't be completed.
    Please give me some helps if you have any idea about it.
    Thanks very much!
    Sirius

    Note that the Nightly build gets updated daily (and sometimes more than once in case of a respin) and it is always possible that something goes wrong and it doesn't work properly, so be prepared for issues if you decide to stay with the Nightly build and make sure to have the current release with its own profile installed as well in case of problems.
    See also:
    * http://kb.mozillazine.org/Testing_pre-release_versions
    *http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows
    *http://kb.mozillazine.org/Shortcut_to_a_specific_profile
    *http://kb.mozillazine.org/Using_multiple_profiles_-_Firefox

  • Error while using Javamail...pls help me...

    when i am using javamail for sending mail , i am getting error like,
    C:\jdk1.3\bin\mail>java MailSend
    [email protected] [email protected]
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    javax.mail.MessagingException:
    at javax.mail.Transport.send0(Transport.java:218)
    at javax.mail.Transport.send(Transport.java:80)
    at MailSend.Send(MailSend.java:56)
    at MailSend.main(MailSend.java:73)
    and i define properties like,
    mailProp.put("java", "java");
    where , "java" is my system name, and there is also mail server on my system. and my system is connected with proxy server..
    when i am trying
    mailProp.put("mail.smtp.host", "java");
    then i am getting same type of error...
    so, what is that ? pls help me to solve my error...

    Surely there's more information associated with that MessaginException than
    you've included here.
    Turn on session debugging and run your program again.
    http://java.sun.com/products/javamail/FAQ.html#debug

  • Trying to send e-mail using JavaMail, JBoss 5, and JNDI

    Hello there,
    Am using JBoss 5.1.0GA and JDK 1.5.0_19 on OS X Leopard.
    Created a working SendMailServlet.
    Have now decided to refactor it into two separate classes (extract out JavaMail code to a separate class and create a ServletController).
    Am also trying to use JNDI to access the connection properties in the mail-service.xml configuration file residing in JBoss.
    The Mailer class contains the reusable functionality needed to send an e-mail:
    public class Mailer {
         private Session mailSession;
         protected void sendMsg(String email, String subject, String body)
         throws MessagingException, NamingException {
              Properties props = new Properties();
              InitialContext ictx = new InitialContext(props);
              Session mailSession = (Session) ictx.lookup("java:/Mail");
    //          Session mailSessoin = Session.getDefaultInstance(props);
              String username = (String) props.get("mail.smtps.user");
              String password = (String) props.get("mail.smtps.password");
              MimeMessage message = new MimeMessage(mailSession);
              message.setSubject(subject);
              message.setRecipients(javax.mail.Message.RecipientType.TO,
                        javax.mail.internet.InternetAddress.parse(email, false));
              message.setText(body);
              message.saveChanges();
              Transport transport = mailSession.getTransport("smtps");
              try {
                   transport.connect(username, password);
                   transport.sendMessage(message, message.getAllRecipients());
                   Logger.getLogger(this.getClass()).warn("Message sent");
              finally {
                   transport.close();
    }The MailController class serves as a standard Java Servlet which invokes the Mailer.class's sendMsg() method:
    public class MailController extends HttpServlet {
         /** static final HTML setting for content type */
         private static final String HTML = "text/html";
         myapp/** static final HTML setting for content type */
         private static final String PLAIN = "text/plain";
         public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
              doPost(request, response);
         public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
              response.setContentType(PLAIN);
              PrintWriter out = response.getWriter();
              String mailToken = TokenUtil.getEncryptedKey();
              String body = "Hello there, " + "\n\n"
                        + "Wanna play a game of golf?" + "\n\n"
                     + "Please confirm: https://localhost:8443/myapp/confirm?token="
                     + mailToken + "\n\n" + "-Golf USA";
              Mailer mailer = new Mailer();
              try {
                   mailer.sendMsg("[email protected]", "Golf Invitation!", body);
                   out.println("Message Sent");
              catch (MessagingException e) {
                   e.printStackTrace();
              catch (NamingException e) {
                   e.printStackTrace();
    }Have the mail configuration set under $JBOSS_HOME/server/default/deploy/mail-service.xml:
    <server>
      <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail">
        <attribute name="JNDIName">java:/Mail</attribute>
        <attribute name="User">user</attribute>
        <attribute name="Password">password</attribute>
        <attribute name="Configuration">
          <configuration>
            <property name="mail.store.protocol" value="pop3"/>
            <property name="mail.transport.protocol" value="smtp"/>
            <property name="mail.user" value="user"/>
            <property name="mail.pop3.host" value="pop3.gmail.com"/>
            <property name="mail.smtp.host" value="smtp.gmail.com"/>
            <property name="mail.smtp.port" value="25"/>
            <property name="mail.from" value="[email protected]"/>
            <property name="mail.debug" value="true"/>
          </configuration>
        </attribute>
        <depends>jboss:service=Naming</depends>
      </mbean>
    </server>web.xml (Deployment Descriptor):
    <servlet>
        <servlet-name>MailController</servlet-name>
        <servlet-class>com.myapp.MailController</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MailController</servlet-name>
        <url-pattern>/sendmail</url-pattern>
    </servlet-mapping>This is what is outputted when I start JBOSS and click point my browser to:
    https://localhost:8443/myapp/sendmail
    [MailService] Mail Service bound to java:/Mail
    [STDOUT] DEBUG: JavaMail version 1.4ea
    [STDOUT] DEBUG: java.io.FileNotFoundException:
    /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/javamail.providers
    (No such file or directory)
    [STDOUT] DEBUG: !anyLoaded
    [STDOUT] DEBUG: not loading resource: /META-INF/javamail.providers
    [STDOUT] DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    [STDOUT] DEBUG: getProvider() returning
    javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
    [STDOUT] DEBUG SMTP: useEhlo true, useAuth false
    [STDOUT] DEBUG SMTP: trying to connect to host "localhost", port 465, isSSL true
    [STDERR] javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 465;
      nested exception is:
         java.net.ConnectException: Connection refused
    [STDERR]      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
    [STDERR]      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    [STDERR]      at javax.mail.Service.connect(Service.java:275)
    [STDERR]      at javax.mail.Service.connect(Service.java:156)
    [STDERR]      at javax.mail.Service.connect(Service.java:176)
    [STDERR]      at com.myapp.Mailer.sendMsg(Mailer.java:45)
    [STDERR]      at com.myapp.MailController.doPost(MailController.java:42)
    [STDERR]      at com.myapp.MailController.doGet(MailController.java:26)Why am I getting this java.net.ConnectException: Connection refused exception?
    Happy programming,
    Mike
    Edited by: mwilson72 on Aug 21, 2009 4:49 PM

    Hi Peter,
    Nice to hear from you again!
    Per your advice, this is what my mail-service.xml config file looks like now:
    <?xml version="1.0" encoding="UTF-8"?>
    <server>
      <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail">
      <attribute name="JNDIName">java:/Mail</attribute>
      <attribute name="User">user</attribute>
      <attribute name="Password">password</attribute>
      <attribute name="Configuration">
         <configuration>
            <property name="mail.store.protocol" value="pop3"/>
         <property name="mail.transport.protocol" value="smtps"/>
            <property name="mail.smtp.starttls.enable" value="true"/>
            <property name="mail.smtps.auth" value="true"/> 
            <property name="mail.user" value="user"/>
            <property name="mail.pop3.host" value="pop3.gmail.com"/>
            <property name="mail.smtp.host" value="smtp.gmail.com"/>
            <property name="mail.smtps.port" value="465"/>
            <property name="mail.from" value="[email protected]"/>
            <property name="mail.debug" value="true"/>
         </configuration>
       </attribute>
       <depends>jboss:service=Naming</depends>
      </mbean>
    </server>Now, when I restart JBoss and point my browser to:
    https://localhost:8443/myapp/sendmail
    I get this exception:
    [STDOUT] DEBUG SMTP: useEhlo true, useAuth true
    [STDOUT] DEBUG SMTP: useEhlo true, useAuth true
    [STDOUT] DEBUG SMTP: trying to connect to host "localhost", port 465, isSSL true
    [STDERR] javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 465;
      nested exception is:
         java.net.ConnectException: Connection refused
    [STDERR] at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
    [STDERR] at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    [STDERR] at javax.mail.Service.connect(Service.java:297)
    [STDERR] at javax.mail.Service.connect(Service.java:156)
    [STDERR] at javax.mail.Service.connect(Service.java:176)
    [STDERR] at com.myapp.Mailer.sendMsg(Mailer.java:45)
    [STDERR] at com.myapp.MailController.doPost(MailController.java:42)
    [STDERR] at com.myapp.MailController.doGet(MailController.java:26)Does anyone know what I am possibly doing wrong? Is it my code or is it the config file?
    -Mike

  • Attachment Problem in JavaMail API

    Can anybody help me...
    when 'm trying to attach a file to a mailing aplication(sending attachment),
    an flurry of exceptions are occuring...
    'm using win98 and JDK1.4
    here is the code..can anybody provide a viable solution that works?
    thanks in advance
    * main1.java
    * Created on August 20, 2002, 2:55 PM
    * @author Shamik Ghosh
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.net.*;
    import java.io.*;
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class main1 extends javax.swing.JFrame implements ActionListener,ItemListener {
    JMenuBar mbar;
    JMenu file,other,help;
    JMenuItem open,save,read_mail;
    JFrame frame_f;
    FileReader fr;
    BufferedReader br;
    boolean check;
    String from_m,smtp_m,from_m1,smtp_m1,result,
    s1,s2,from_server,from_host,to_file,which_file,attach_text;
    File f;
    /** Creates new form main1 */
    public main1() {
    initComponents();
    setSize(550,500);
    setResizable(false);
    // ------------------------centering the display
    int width=550; // note that "width" & "height" are keywords and
    int height=500; // JAVA defined variables.
    Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
    int x=(screen.width-width)/2;
    int y=(screen.height-height)/2;
    setBounds(x,y,width,height);
    try{
    fr=new FileReader("address.txt");
    br=new BufferedReader(fr);
    String s;
    while((s=br.readLine()) !=null)
    {jComboBox1.addItem(s);}
    fr.close();
    }catch(Exception e){ System.out.println(e);}
    check_info();//calling the method to check the info
    //jTextField1.setText(from_m);
    //jTextField3.setText(smtp_m);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {//GEN-BEGIN:initComponents
    buttonGroup1 = new javax.swing.ButtonGroup();
    buttonGroup2 = new javax.swing.ButtonGroup();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jTextField3 = new javax.swing.JTextField();
    jComboBox1 = new javax.swing.JComboBox();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jLabel4 = new javax.swing.JLabel();
    jRadioButton3 = new javax.swing.JRadioButton();
    jRadioButton4 = new javax.swing.JRadioButton();
    jButton4 = new javax.swing.JButton();
    jButton6 = new javax.swing.JButton();
    jButton5 = new javax.swing.JButton();
    jTextField4 = new javax.swing.JTextField();
    jLabel5 = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTextArea2 = new javax.swing.JTextArea();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jLabel10 = new javax.swing.JLabel();
    //actionlisteners
    jButton1.addActionListener(this);
    jButton2.addActionListener(this);
    jButton3.addActionListener(this);
    jButton4.addActionListener(this);
    jButton5.addActionListener(this);
    jButton6.addActionListener(this);
    mbar=new JMenuBar();
    setJMenuBar(mbar);
    file=new JMenu("File");
    other=new JMenu("Other");
    help=new JMenu("Help");
    mbar.add(file);
    mbar.add(other);
    mbar.add(help);
    getContentPane().setLayout(null);
    setTitle("MailMan :Designed and Programmed by Shamik Ghosh");
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    jLabel1.setText("From:");
    getContentPane().add(jLabel1);
    jLabel1.setBounds(30, 20, 32, 17);
    jLabel2.setText("To:");
    getContentPane().add(jLabel2);
    jLabel2.setBounds(30, 60, 17, 17);
    getContentPane().add(jTextField1);
    jTextField1.setBounds(110, 20, 240, 21);
    getContentPane().add(jTextField2);
    jTextField2.setBounds(110, 60, 240, 21);
    jLabel3.setText("Smtp Server:");
    getContentPane().add(jLabel3);
    jLabel3.setBounds(10, 100, 74, 17);
    getContentPane().add(jTextField3);
    jTextField3.setBounds(110, 100, 240, 21);
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {  }));
    jComboBox1.setToolTipText("Mail Addresses");
    jComboBox1.setAutoscrolls(true);
    jComboBox1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jComboBox1ActionPerformed(evt);
    getContentPane().add(jComboBox1);
    jComboBox1.setBounds(110, 150, 240, 20);
    jComboBox1.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
    jButton1.setToolTipText("Send the message you have typed");
    jButton1.setMnemonic('m');
    jButton1.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
    jButton1.setText("Send Mail");
    getContentPane().add(jButton1);
    jButton1.setBounds(370, 300, 160, 25);
    //jButton2.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 12));
    jButton2.setText("Save Info");
    jButton2.setToolTipText("Save Settings for more mails");
    jButton2.setMnemonic('I');
    getContentPane().add(jButton2);
    jButton2.setBounds(370, 340, 160, 25);
    jButton3.setText("Clear ");
    jButton3.setMnemonic('C');
    jButton3.setToolTipText("Clear all text");
    getContentPane().add(jButton3);
    jButton3.setBounds(370, 380, 160, 27);
    jLabel4.setText("Your Contact Addresses");
    jLabel4.setFont(new java.awt.Font("Arial Narrow", 0, 12));
    getContentPane().add(jLabel4);
    jLabel4.setBounds(110, 130, 200, 15);
    jRadioButton3.setText("Use Log File");
    jRadioButton3.setMnemonic('L');
    getContentPane().add(jRadioButton3);
    jRadioButton3.setBounds(260, 310, 90, 25);
    jRadioButton4.setText("No Log File");
    //jRadioButton4.setMnemonic('N');
    //getContentPane().add(jRadioButton4);
    //jRadioButton4.setBounds(260, 340, 86, 25);
    jButton4.setText("Undo Info");
    jButton4.setMnemonic('U');
    jButton4.setToolTipText("Undo settings");
    getContentPane().add(jButton4);
    jButton4.setBounds(260, 380, 87, 27);
    getContentPane().add(jTextField4);
    jTextField4.setBounds(20, 380, 210, 21);
    jLabel5.setText("Attachment");
    jLabel5.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
    getContentPane().add(jLabel5);
    jLabel5.setBounds(70, 360, 70, 15);
    jButton5.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
    jButton5.setText("Browse");
    jButton5.setMnemonic('B');
    jButton5.setToolTipText("Browse files for Attachment");
    getContentPane().add(jButton5);
    jButton5.setBounds(150, 350, 80, 25);
    jButton6.setText("Attach & Send");
    jButton6.setMnemonic('A');
    jButton6.setToolTipText("Attach File & Send Mail");
    getContentPane().add(jButton6);
    jButton6.setBounds(260, 340, 86, 25);
    jScrollPane1.setViewportView(jTextArea1);
    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(370, 20, 160, 270);
    jLabel10.setText("Type your mail:");
    jLabel10.setFont(new java.awt.Font("Abadi MT Condensed Light", 1, 12));
    getContentPane().add(jLabel10);
    jLabel10.setBounds(370, 5, 125, 10);
    jScrollPane2.setViewportView(jTextArea2);
    getContentPane().add(jScrollPane2);
    jScrollPane2.setBounds(20, 200, 340, 90);
    jLabel6.setText("(your ISP smtp)");
    jLabel6.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
    getContentPane().add(jLabel6);
    jLabel6.setBounds(10, 120, 70, 12);
    jLabel7.setText("porgrammed and designed by : Shamik Ghosh");
    jLabel7.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
    getContentPane().add(jLabel7);
    jLabel7.setBounds(260, 410, 160, 12);
    jLabel8.setText("[email protected]");
    jLabel8.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
    getContentPane().add(jLabel8);
    jLabel8.setBounds(420, 410, 80, 12);
    jLabel9.setText("Msg.for the Mail Sent:");
    jLabel9.setForeground(java.awt.Color.black);
    jLabel9.setFont(new java.awt.Font("Abadi MT Condensed Light", 0, 10));
    getContentPane().add(jLabel9);
    jLabel9.setBounds(20, 180, 80, 12);
    file.add(open=new JMenuItem("Open"));
    open.setAccelerator(KeyStroke.getKeyStroke('O',Event.CTRL_MASK,true));
    file.addSeparator();
    file.add(save=new JMenuItem("Save"));
    save.setAccelerator(KeyStroke.getKeyStroke('S',Event.CTRL_MASK,true));
    file.addSeparator();
    other.add(read_mail=new JMenuItem("Add Address"));
    read_mail.setAccelerator(KeyStroke.getKeyStroke('A',Event.CTRL_MASK,true));
    other.addSeparator();
    //adding actionListener to menuitems
    open.addActionListener(this);
    save.addActionListener(this);
    read_mail.addActionListener(this);
    jComboBox1.addItemListener(this);
    pack();
    }//GEN-END:initComponents
    public void itemStateChanged(ItemEvent ie)
    String add_list;
    add_list=String.valueOf(jComboBox1.getSelectedItem());
    jTextField2.setText(add_list);
    } // for item event source
    public void actionPerformed(ActionEvent ae)
    if(ae.getSource()==jButton1)
    if(ae.getSource()==jButton1) {
    SwingUtilities.invokeLater(new Runnable()
    {  public void run()
    sendMail();
    if(ae.getSource()==jButton2) //save info
    from_m =jTextField1.getText();
    smtp_m =jTextField3.getText();
    from_m1 =from_m+"\n";
    smtp_m1 =jTextField3.getText();
    result =from_m1+smtp_m1;
    try{
    byte buf[]=result.getBytes();
    OutputStream fo=new FileOutputStream("info.txt");
    for(int i=0;i<buf.length; i++ )
    fo.write(buf);
    fo.close();
    }catch(Exception e){ System.out.println(e);}
    jTextField1.setEditable(false);
    jTextField3.setEditable(false);
    if(ae.getSource()==jButton3) //clear
    jTextArea1.setText(" ");
    jTextArea2.setText(" ");
    if(ae.getSource()==jButton4)//undo info
    jTextField1.setEditable(true);
    jTextField3.setEditable(true);
    if(ae.getSource()==jButton5)//browse for attachment
    try {
    FileDialog file = new FileDialog (main1.this, "Load File", FileDialog.LOAD);
    file.setFile ("*.*"); // Set initial filename filter
    file.show(); // Blocks
    String curFile;
    if ((curFile = file.getFile()) != null) {
    String filename = file.getDirectory() + curFile;
    char[] data;
    setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    f = new File (filename);
    try {
    System.out.println("INSIDE TRY");
    FileReader fin = new FileReader (f);
    int filesize = (int)f.length();
    data = new char[filesize];
    fin.read (data, 0, filesize);
    setCursor (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    } catch (Exception exc) {}
    jTextField4.setText(filename);
    } catch(Exception e){}
    if(ae.getSource()==jButton6)//send attachment & Mail
    try{
    sendmail2();
    }catch(Exception e){}
    if(ae.getSource()==open)//menu open
    if(ae.getSource()==save)//menu save
    if(ae.getSource()==read_mail)//menu read_mail
    address_add();
    } //actionperformed
    public void sendmail2()
    try {
    //which_file,attach_text
    from_server=jTextField3.getText();
    from_host=jTextField1.getText();
    to_file=jTextField2.getText();
    which_file=jTextField4.getText();
    attach_text=jTextArea1.getText();
    //getting system property
    Properties props=System.getProperties();
    //setup mail server
    props.put("mail.smtp.host",from_server);
    //get session
    Session session=Session.getInstance(props,null);
    // Define message
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from_host));
    message.addRecipient(Message.RecipientType.TO,
    new InternetAddress(to_file));
    message.setSubject("Hello JavaMail Attachment");
    //define message part
    BodyPart messageBodyPart=new MimeBodyPart();
    // Fill the message
    messageBodyPart.setText(attach_text);
    // Create a Multipart
    Multipart multipart = new MimeMultipart();
    // Add part one
    multipart.addBodyPart(messageBodyPart);
    //attaching**********************************secon Part Attachment
    //creating second body part
    messageBodyPart=new MimeBodyPart();
    DataSource source=new FileDataSource(which_file); //was filename
    //setting data handler to the attachment
    messageBodyPart.setDataHandler(new DataHandler(source));
    //setting the filename
    messageBodyPart.setFileName(which_file);
    //adding part two
    multipart.addBodyPart(messageBodyPart);
    //put parts in the message
    message.setContent(multipart);
    //Sending msg
    Transport.send(message);
    }catch(Exception e){}
    } //sendmail2
    public void address_add()
    addr=jTextField2.getText();
    str_addr=addr+"\n";
    //jComboBox1.addItem(" ");
    jComboBox1.addItem(addr);
    System.out.println("INSIDE WRITING METHOD");
    try{
    byte buf[]=str_addr.getBytes();
    OutputStream f0=new FileOutputStream("address.txt",true);
    for(int i=0;i<buf.length; i++ )
    f0.write(buf[i]);
    f0.close();
    }catch(Exception e){ System.out.println(e);}
    public void check_info()
    try{
    fr=new FileReader("info.txt");
    br=new BufferedReader(fr);
    while((s1=br.readLine()) !=null && (s2=br.readLine()) !=null)
    jTextField1.setText(s1);
    jTextField3.setText(s2);
    break;
    fr.close();
    }catch(Exception e){ System.out.println(e);}
    public void sendMail()
    {  try
    Socket s = new Socket(jTextField3.getText(), 25);
    out = new PrintWriter(s.getOutputStream());
    in = new BufferedReader(new
    InputStreamReader(s.getInputStream()));
    String hostName
    = InetAddress.getLocalHost().getHostName();
    send(null);
    send("Host " + hostName);
    send("Mail FROM: " + jTextField1.getText());
    send("Rcpt TO: " + jTextField2.getText());
    send("Data");
    out.println(jTextArea1.getText());
    send(".");
    s.close();
    catch (IOException exception)
    {  jTextArea2.append("Error: " + exception);
    String err="Message cannot be sent!"+"\n"
    +"Please verify the setting(s)."+
    "\n"+"Else there may be a NetWork Problem."+
    "\n"+"Please verify and Try Again.";
    JOptionPane.showMessageDialog(frame_f,err,"Message Transmission Failure",JOptionPane.ERROR_MESSAGE);
    public void send(String s) throws IOException
    {  if (s != null)
    {  jTextArea2.append(s + "\n");
    out.println(s);
    out.flush();
    String line;
    if ((line = in.readLine()) != null)
    jTextArea2.append(line + "\n");
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
    // Add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
    System.exit(0);
    }//GEN-LAST:event_exitForm
    * @param args the command line arguments
    public static void main(String args[]) {
    new main1().show();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JButton jButton4;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabel10;
    private BufferedReader in;
    private PrintWriter out;
    private String addr,str_addr;
    // End of variables declaration//GEN-END:variables

    Hi I have this problem which I believe you can help me resolve:
    In my code, there are two lines:
    message.setContent(messageBody, "text/html"); // this sets body of message
    message.setContent(bodyPartObject); // this attaches a file
    but it turns out that the second "setContent" statement over-writes the first one, so that I get no message in the body of the mail.
    What can I do about it, shamik1? Thanks!

  • Is there any limit of JavaMail for sending mails?

    When am sending more than 700 mails at a time then error appears that "server is too busy please try again"
    Is there any deficiency in my code or limitations in JavaMail ?
    Thanks & best regards

    The limitation is in your server.

  • Javax.mail.MessagingException: 451 4.3.2 Please try again later

    Hi,
    Can any one help out to fix following problem.
    exception occurred :Sending failed;
    nested exception is:
         javax.mail.MessagingException: 451 4.3.2 Please try again later

    If this is generated by the server at random, I do not think javamail can not do anything about it. You can add retry logic in your code or figure out why server is giving this error (configuration issue? need to increase any parameters on the server side?).

  • JavaMail, ESMTP, problem with this server response: "+  stunnel"

    I need to send message through a STMP server I don't know much about. The server works fine, when using port 25. But I need to send mail through port 465. I've looked around the web, I've searched the forums, but found no solution.
    I've identified, that the server uses some kind of strange "secure" connection. I was told, that is uses SSL, but when I use SMTPSSLTransport, it says the "Unrecognized SSL, plaintext connection?". So I am using the common Transport. This is my code:
                props.put("mail.transport.protocol","smtps");
                props.put("mail.smtp.host", smtpHost);
                props.put("mail.smtp.port", 465);           
                props.put("mail.smtps.starttls.enable","true");
                props.put("mail.smtps.ssl", "true");
                props.put("mail.smtps.socketFactory.port", 465);
                props.put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                Session session = Session.getDefaultInstance(props);
                session.setDebug(true);
                Transport transport = session.getTransport();
    ...I am getting this output:
    DEBUG: setDebug: JavaMail version 1.4.1
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "host name of the server", port 465, isSSL false
    220 "host name of the server" ESMTP Sendmail 8.13.1/8.13.1; Fri, 15 Feb 2008 18:10:49 +0100
    + stunnelDEBUG SMTP: connected to host "host name of the server", port: 465
    EHLO "my hostname"
    DEBUG SMTP: bad server response:  + stunnel
    HELO "my hostname"
    250-"my hostname"
    WelcomeDEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    250 STARTTLS
    220 Go ahead
    RCPT TO:<[email protected]>
    DEBUG SMTP: got response code 220, with response: 220 Go ahead
    RSET
    DEBUG SMTP: exception reading response: java.net.SocketException: Connection reset
    javax.mail.MessagingException: Exception reading response;
      nested exception is:
            java.net.SocketException: Connection resetI have no idea, what a stunnel is, but it is causing the problem, I think.
    Does anybody have any ideas what can be wrong? Or does anyone know how to check the server setting? Or what properties can I try to set? (I've tried all possible options of the properties I am already setting in the code).

    You're getting newline (LF without the CR)? If so,
    it's possible that Thunderbird isn't seeing that as
    an end of line and so considers the "+stunnel" to
    be part of the greeting line.
    Either way, there's something messed up in the
    server configuration and you really need to report
    that to the server administrator.
    Also, port 465 is supposed to be an SSL port,
    starting in SSL mode, not starting in plain text
    mode as you're seeing. Again, this is evidence
    that the server is set up incorrectly.
    JavaMail will support STARTTLS just fine, and it
    won't care what port you're using, but that bogus
    "+stunnel" line is a protocol violation that's
    confusing it. Possibly Thunderbird is taking the
    approach of "throw away garbage until I see
    something I recognize", but JavaMail isn't working
    that way.
    If this was a server on the public internet that
    lots of people might encounter, I might be inclined
    to add a workaround to JavaMail. But since this is
    a private server that's clearly configured incorrectly
    and is clearly violating the protocol, I think the best
    thing to do is to get the server fixed.

  • JSP and JavaMail

    I have this Javamail program that I know works and I'm trying to put it into JSP. Since I'm still new to JSP, I can't figure out why I'm getting this error:
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\tomcat\work\localhost\ams\index$jsp.java:11: Package javax.mail not found in import.
    import javax.mail.*;
    ^
    C:\tomcat\work\localhost\ams\index$jsp.java:12: Package javax.mail.internet not found in import.
    import javax.mail.internet.*;
    I just can't get the javamail stuff to work in JSP. Could you tell me why?
    Thank you in advance,
    Mike

    hmm...no, I have the javamail package on my c:\
    This is what my CLASSPATH looks like:
    .;C:\ServletDevel;C:\tomcat\common\lib\servlet.jar;C:\javamail-1.2\mail.jar;C:\jaf-1.0.1\activation.jar
    Question 1
    Should I just change the location of the javamail and jaf folders to:
    C:\tomcat\lib or C:\tomcat\common\lib ???
    and change the CLASSPATH??
    Question 2
    or should I just download it again and add to the CLASSPATH rather than change it???? And again, which lib directory? C:\tomcat\lib or C:\tomcat\common\lib ???
    Thanks again,
    Mike

  • 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?

  • How to use setContent() in javamail

    I want to send a mail through Jsp page. My code for to do this is given below.It sends the mail but the problem is that it prints the Html code as it is in the text that is send through mail.. for example if i write message.setText("testing<br>hello"); than it prints message<br>hello as mail text instead of taking the break after testing.... pl reply soon...
    <%@ page import="javax.mail.*, javax.mail.internet.*, java.io.*, javax.mail.event.*, java.net.*, java.util.*" %>
    <%
    Properties props=new Properties();
    props.put("mail.smtp.host","mail.infobase.in");
              Session session1 = Session.getDefaultInstance(props,null);
    MimeMessage message =new MimeMessage(session1);
    message.setFrom(new InternetAddress("[email protected]"));
    message.setRecipients
    (Message.RecipientType.TO,InternetAddress.parse("[email protected]",false));
    message.setSubject("hello");
    message.setText("testing<br>hello");
    Transport.send(message);
    out.println("mail has been sent");
    %>

    In JavaMail 1.4:
    http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimeMessage.html#setText%28java.lang.String,%20java.lang.String,%20java.lang.String%29
    Is there something about the way that's written that makes it hard to understand?
    Again, in earlier versions of JavaMail this was more difficult.
    The key line from the sendhtml.java demo program (were you
    unable to find it?) is:
    msg.setDataHandler(new DataHandler(
                    new ByteArrayDataSource(sb.toString(), "text/html")));

  • New to JavaMail: sending via MS Outlook

    i was searching the forum for quite some time, i just couldn't find what i am looking for. sorry if similar question has been posted.
    all i want to do is:
    1) send an email via outlook, that means in my application i set all the parameters like recipient, subject, content and then i want outlook to start and send the e-mail
    2) i managed somehow with "cmd /c start mailto:" but it would be nice to send the mail automatically, not just open the dialog.
    3) i managed to send emails with the JavaMail API, but then the outgoing message is not stored in outlook.
    what do i need to do? i really appreciate any answers...
    thanks, steff

    thank you again and sorry for bothering you. what i am trying to tell you is, that i am not using/do not have a server. all i have is a normal ms office outlook (local client, there is no server behind that) ... to send the message i only make a smtp-connection to my internet service providers mail-server (like outlook does as well). but i am not interested in the isp folders.
    i had a close look at the examples you said (mover.java & folderlist.java) and again, there is this IMAP connecntion to A server.
    Am I completely wrong, or do i just don't understand it. i want to save messages local in my outlook (unfortunatelly no server). Could you make an example for me to understand?
    thanks again, stefan

  • Sending a notification using MDB, javamail and a scheduler

    Hi,
    I have this following scenario.
    I need to send an email notification to user B from user A.
    So, user A fills the required details and adds the notification object to jms/queue
    In MessageDriveBean onMessage(), i am getting the notification object from the queue
    and i am able to send an email using JavaMail.
    Everything is working fine.
    Now , if under any conditions, sending notification fails, I need to implement
    a scheduler which should try to send the notification within the specified time interval
    and if not again adds the notification object to queue.
    Can you please help me to implement a scheduler?
    Thanks in advance!!!

    Have a look at this simple schedular below, test by changing the method onMessage() to a main method
    and simulate.
    Hope this help
    Ivo Sumelong
    * @author isumelong
    public class MessageFromQueueMDBHandler {
         * @param args the command line arguments
        public  void onMessage() {
             MessageFromQueueMDBHandler m=new MessageFromQueueMDBHandler();
             m.hanldeMessageFromQuue();
      public synchronized  void  hanldeMessageFromQuue()
    // Thread.sleep() is not good since its a static method this
    // why wait will be best since it controls only the thread
    // that received the messgae from the queue
    //schedular information read from database
    // numberOfTrials,waitingTimeBeforeResending;
    // advantage: schedular behaviour could be changed at run time
    int numberOfTrials=4;// from database
          try {
                for(int i=0;i<System.currentTimeMillis();i++)
                    if(sendMail())
                    break;
                    if(i==numberOfTrials)
                       // send an message to queue
                       sendMessageToQueue();
                    notifyAll();
                         break;
                  long waitingTimeBeforeResending=1000;// from database
                this.wait(waitingTimeBeforeResending);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
      private boolean sendMail()
      // java mail API accesses
          return true;
       private boolean sendMessageToQueue()
      // java JMS API accesses
          return true;
    }

  • Hi javamail pop3 problem

    hello...
    i have a written code for retrieving mail from pop3 server...and its working fine except one problem....(if it is a problem)....
    when i retrieve mails i open outlook express and it again retrieves the same mails i have retirieved from my code....is this a normal behaviour as pop3 deletes all the retrieved messages....and when i first receive message using outlook my code is unable to find those messages .....so why this difference....should my code deliberately and explicitly delete messages after retrieving them or pop3 does it as its default behaviour....

    The emails on the POP3 server are not deleted from the server as they retrieved.
    In Outlook Express as well as in Outlook you can set the properties for your email account to leave a copy of the message on the server. The initial setting is to delete the message from the server as you retrieve it.
    In JavaMail in order to delete the email from the server you need to open the folder object for Read/Write, then to set the DELETED flag on the message to �true�;
    When you close the folder, deleted messages will be removed if you set the expunge parameter to �true�.
    As in the following code:
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    Message message = folder.getMessage(1);
    message.setFlag(Flags.Flag.DELETED, true);
    folder.close(true);

  • Packaging in JAR makes JavaMail not work

    I have simple code (virtually identical to the demo code that comes with JavaMail 1.3) to send an email with an attachment that works fine until i package it in a JAR file and try and use javaw to run it. I have included the mail.jar and activation.jar files in the app JAR file with no success. Once again the code works fine outside of a JAR file.
    -thanks
    benji
    Properties props = System.getProperties();
    props.put("mail.smtp.host", server);
    props.put("mail.from",from);
    Session session = Session.getInstance(props, new myAuthenticator());
    session.setDebug(debug);
    try
    MimeMessage msg = (MimeMessage)new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(subject);
    MimeBodyPart mbp1 = (MimeBodyPart)new MimeBodyPart();
    mbp1.setText(message);
    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource(sendFile);
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    msg.setContent(mp);
    msg.setSentDate(new Date());
    Transport.send(msg);
    return true;
    catch statements

    Correct, a JAR Executable, no i did not enter the mail.jar and activation.jar as "Class Path" files in the app jar. i used the following command:
    C:\j2sdk_nb\j2sdk1.4.2\bin\jar vcm0f mainClass4.txt ZipperS.jar C:\javamail-1_3_1\mail.jar C:\jaf-1_0_2\activation.jar ZipperS.class (more classes)
    where the file mainClass4.txt contains:
    Main-Class: ZipperS
    How do you specify mail.jar and activation.jar as class path entries?
    thanks

Maybe you are looking for