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!

Similar Messages

  • Problem Sending mails in a loop using JavaMail API

    Hello All,
    I am sending emails in a loop(one after the other) using JavaMail API,but the problem is, if the first two,three email addresses in the loop are Valid it sends the Email Properly, but if the Fourth or so is Invalid Address it throws an Exception....
    "javax.mail.SendFailedException: Sending failed;"
    nested exception is:
    javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    javax.mail.SendFailedException: 450 <[email protected]>:Recipient address rejected: Domain not found......
    So if i want to send hundereds of emails and if one of the Emails inbetween is Invalid the process Stops at that point and i could not send the other emails in the Loop......
    How Could i Trap the exception thrown and handle it in such a way, so that the loops continues ..
    Is there something with the SMTP Server....?
    The code which i am using is as follows....
    <Code>...
    try {
    InitialContext ic = new InitialContext();
    Session session = (Session) ic.lookup(JNDINames.MAIL_SESSION);
    if (Debug.debuggingOn)
    session.setDebug(true);
    // construct the message
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(eMess.getEmailSender()));
    String to = "";
    msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(to, false));
    msg.setRecipients(Message.RecipientType.BCC,
    InternetAddress.parse(eMess.getEmailReceiver(), false));
    msg.setSubject(eMess.getSubject());
    msg.setContent(eMess.getHtmlContents(),"text/plain");
    msg.saveChanges();                
    Transport.send(msg);
    } catch (Exception e) {
    Debug.print("createAndSendMail exception : " + e);
    throw new MailerAppException("Failure while sending mail");
    </Code>....
    Please give me any suggestions regarding it....and guide me accordingly..
    Thanks a million in advance...
    Regards
    Sam

    How about something like the code attached here. Be aware it is lifted and edited out of an app we have here so it may require changing to get it to work. If it don't work - don't come asking for help as this is only a rough example of one way of doing it. RTFM - that's how we worked it out!
    SH
    try {
    Transport.send(msg);
    // If we get to here then the mail went OK so update all the records in the email as sent
    System.out.println("Email sent OK");
    catch (MessagingException mex) {
    System.out.println("Message error");
    Exception ex = mex;
    do {
    if (ex instanceof SendFailedException) {
    if (ex.getMessage().startsWith("Sending failed")) {
    // Ignore this message as we want to know the real reason for failure
    // If we get an Invalid Address error or a Message partially delivered message process the message
    if (ex.getMessage().startsWith("Message partially delivered")
    || ex.getMessage().startsWith("Invalid Addresses")) {
    // This message is of interest as we need to process the actual individual addresses
    System.out.println(ex.getMessage().substring(0, ex.getMessage().indexOf(";")));
    // Now get the addresses from the SendFailedException
    SendFailedException sfex = (SendFailedException) ex;
    Address[] invalid = sfex.getInvalidAddresses();
    if (invalid != null) {
    System.out.println("Invalid Addresse(s) found -");
    if (invalid.length > 0) {
    for (int x = 0; x < invalid.length; x++) {
    System.out.println(invalid[x].toString().trim());
    Address[] validUnsent = sfex.getValidUnsentAddresses();
    if (validUnsent != null) {
    System.out.println("Valid Unsent Addresses found -");
    if (validUnsent.length > 0) {
    for (int x = 0; x < validUnsent.length; x++) {
    System.out.println(validUnsent[x].toString().trim());
    Address[] validSent = sfex.getValidSentAddresses();
    if (validSent != null) {
    System.out.println("Valid Sent Addresses found -");
    if (validSent.length > 0) {
    for (int x = 0; x < validSent.length; x++) {
    System.out.println(validSent[x].toString().trim());
    if (ex instanceof MessagingException)
    ex = ((MessagingException) ex).getNextException();
    else {
    // This is a general catch all and we should assume that no messages went and should stop
    System.out.println(ex.toString());
    throw ex;
    } while (ex != null);

  • Problem accessing gmail with IMAP using JavaMail APIs

    Hi,
    I am trying to access my gmail account with JavaMail API. I am able to access it using pop3s but not with IMAP.
    I have used following details:
    protocol: imap
    host: imap.gmail.com
    port: -1 (also tried with 993) but no success.
    My basic code is
    url = new URLName(protocol, getHostname(), 993, mbox,
                              getUsername(), getPassword());
             Properties props = null;
             try {
              props = System.getProperties();
             } catch (SecurityException sex) {
              props = new Properties();
             session = Session.getInstance(props, null);
              session.setDebug(true);
            store = session.getStore(url);
            store.connect();
            folder = store.getFolder(url);
            folder.open(Folder.READ_WRITE);Any pointers?
    Thanks.

    Changed protocol from "imap" to "imaps"....and used port 993...and its working!!!!

  • Getting error when sending SMTP mail using javamail api

    hi all
    i am new to javamail api...and using it first-time....i'v used the following code
    <%
    String mailHost="mail.mastsale.com";
    String mailText="Hello this is a test msg";
    String to="<a href="mailto:[email protected]">[email protected]</a>";
    String subject="jsp test mail";
    try
    String from="<a href="mailto:[email protected]">[email protected]</a>";
    String mailhost = "mail.mastsale.com";
    Properties props = System.getProperties();
    props.put("mail.smtp.host", mailhost);
    // Get a Session object
    Authenticator auth = new SMTPAuthenticator( "<a href="mailto:[email protected]">[email protected]</a>", "abcd" );
    Session session1 = Session.getInstance(props,auth);
    //Session.setDebug(true);
    //construct message
    Message msg = new MimeMessage(session1);
    msg.setFrom(new InternetAddress(from,"Your Name"));
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
    msg.setSubject(subject);
    msg.setText(mailText);
    //msg.setHeader("X-Mailer",mailer);
    msg.setSentDate(new Date());
    msg.saveChanges();
    //Send the message
    out.println("Sending mail to " + to);
    Transport.send(msg);
    catch (MessagingException me)
    out.println("Error in sending message for messaging exception:"+me);
    %>
    and
    SMTPAuthenticator.java
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class SMTPAuthenticator extends javax.mail.Authenticator {
    private String fUser;
    private String fPassword;
    public SMTPAuthenticator(String user, String password) {
    fUser = user;
    fPassword = password;
    public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(fUser, fPassword);
    Now getting error as: Error in sending message for messaging exception:javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 550-(host.hostonwin.com) [208.101.41.106] is currently not permitted to relay 550-through this server. Perhaps you have not logged into the pop/imap server 550-in the last 30 minutes or do not have SMTP Authentication turned on in your 550 email client.
    Can anyone help me?

    i got the following error while using the below code,
    -----------registerForm----------------
    DEBUG: setDebug: JavaMail version 1.3.2
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    :::::::::::::::::::::::::::::::::<FONT SIZE=4 COLOR="blue"> <B>Error : </B><BR><HR> <FONT SIZE=3 COLOR="black">javax.mail.AuthenticationFailedException<BR><HR>
    -----------registerForm----------------
    public class SendMailBean {
    public String send(String p_from, String p_to, String p_cc, String p_bcc,
    String p_subject, String p_message, String p_smtpServer,String FilePath) {
    String l_result = "";
    // Name of the Host machine where the SMTP server is running
    String l_host = p_smtpServer;
    //for file attachment
    String filename = FilePath;
    // Gets the System properties
    Properties l_props = System.getProperties();
    // Puts the SMTP server name to properties object
    l_props.put("mail.smtp.host", l_host);
    l_props.put("mail.smtp.auth", "true");
    // Get the default Session using Properties Object
    Session l_session = Session.getDefaultInstance(l_props, null);
    l_session.setDebug(true); // Enable the debug mode
    try {
    MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
    l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
    // Setting the "To recipients" addresses
    l_msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(p_to, false));
    // Setting the "Cc recipients" addresses
    l_msg.setRecipients(Message.RecipientType.CC,
    InternetAddress.parse(p_cc, false));
    // Setting the "BCc recipients" addresses
    l_msg.setRecipients(Message.RecipientType.BCC,
    InternetAddress.parse(p_bcc, false));
    l_msg.setSubject(p_subject); // Sets the Subject
    // Create and fill the first message part
    MimeBodyPart l_mbp = new MimeBodyPart();
    //123
    ///////l_mbp.setText(p_message);
    l_mbp.setContent(p_message,"text/html");
    // Create the Multipart and its parts to it
    Multipart l_mp = new MimeMultipart();
         //l_mp.setContent(html,"text/html");
    l_mp.addBodyPart(l_mbp);
    // Add the Multipart to the message
    l_msg.setContent(l_mp,"text/html");
    // Set the Date: header
    l_msg.setSentDate(new Date());
    //added by cibijaybalan for file attachment
         // attach the file to the message
    //Multipart l_mp1 = new MimeMultipart();
         if(!filename.equals(""))
                   String fname = filename;
                   MimeBodyPart mbp2 = new MimeBodyPart();
                   FileDataSource fds = new FileDataSource(fname);
                   mbp2.setDataHandler(new DataHandler(fds));
                   mbp2.setFileName(fds.getName());
                   l_mp.addBodyPart(mbp2);
              // add the Multipart to the message
              l_msg.setContent(l_mp);
    //ends here
         l_msg.setSentDate(new java.util.Date());
    // Send the message
    Transport.send(l_msg);
    // If here, then message is successfully sent.
    // Display Success message
    l_result = l_result + "Mail was successfully sent to : "+p_to;
    //if CCed then, add html for displaying info
    //if (!p_cc.equals(""))
    //l_result = l_result +"<FONT color=green><B>CCed To </B></FONT>: "+p_cc+"<BR>";
    //if BCCed then, add html for displaying info
    //if (!p_bcc.equals(""))
    //l_result = l_result +"<FONT color=green><B>BCCed To </B></FONT>: "+p_bcc ;
    //l_result = l_result+"<BR><HR>";
    } catch (MessagingException mex) { // Trap the MessagingException Error
    // If here, then error in sending Mail. Display Error message.
    l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
    "<FONT SIZE=3 COLOR=\"black\">"+mex.toString()+"<BR><HR>";
    } catch (Exception e) {
    // If here, then error in sending Mail. Display Error message.
    l_result = l_result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+
    "<FONT SIZE=3 COLOR=\"black\">"+e.toString()+"<BR><HR>";
    e.printStackTrace();
    }//end catch block
    //finally {
    System.out.println(":::::::::::::::::::::::::::::::::"+l_result);
    return l_result;
    } // end of method send
    } //end of bean
    plz help me

  • Question about using JavaMail API to read the calendar folder...

    Hi,
    I've made an application that goes to the mail server, fetches all mails in the calendar folder and tells you the meetings you have in a particular day.
    I'm using JavaMail API for this. My problem is that the application is very slow because I'm forced to fetch (one by one!) the contents of every message.
    My question is: How can Outlook show so fast the mettings you have? Do they have a specific API that allows them to get the right info by only calling certain methods? Is there something similar in Java?
    Thaks for your help!
    Note: I use method:
    folder.fetch(allMessages, fetchProfile);howerver the fetchProfile class does not allow me to specfy that I want to dowload the contents of the message (you only can specify the content_info); specifying all headears does not help me either.

    Clarification:
    The VI you have posted will work as following:
    1) The task will read 2 analog inputs (ai0, ai3).
    2) The acquisition starts, oncece digital signal (trigger) is detected on PFI0
    3) The sampling rate will be as specified in "rate" control - it is continuous analog input acquisition, which means that after trigger is received (point 2), the board will start to generate hardware clock with frequency you specify as "rate"
    4) with each rising edge of that hardware clock, the measurement is taken, and stored into buffer of driver.
    5) DAQmx read will try to read "number of samples per channel" number of samples each time is called - and if there is not enough measurement stored in buffer (step 4), then DAQmx read will wait until DAQ card will measure reaquested number of samples (or timeout occurs before requested number of samples has been acquired)
    6) DAQmx read will be then called 1000 times - so totaly you will read 1000 * "number of samples per channel"  number of samples.
    You do not have to be worried about speed of the loop. In fact, if you need to read just 1000 samples, with 1kS/s, then you can remove for loop and you can change measurement mode from continuous to finite samples, and specify number of samples to read to be 1000. You will read them all properly. I recomend you to read User Manual for your DAQ device - lets say M Series User Manual.
    I hope it is clear now.
    regards,
    stefo

  • Order, Paginate and List  emails in JavaMail API

    Am able to sendm and retrieve emails in java using JavaMail API but am having a problem. I would like to sort emails by date, subject, sender etc and also display only a subset of emails using pagination.
                Message[] msgs = folder.getMessages();
                FetchProfile fp = new FetchProfile();
                fp.add(FetchProfile.Item.ENVELOPE);
                folder.fetch(msgs, fp);The function folder.getMessages(); can take 2 arguments (from_index,to_index), but this is according to the way mail server will transalate. POP server will arrange by date while IMAP is unordered. I would like to order the mails then fetch the getMessages(from_index,to_index).
    Another posible way am seeing is fetching all mesages using getMessages() put them in a temporary storage(eg. vector or list), order them and then fetch only the page i want. But this could be very costly in terms of processing resources, which makes me believe there is a better approach and it seems i cant find it.
    Can somenone please advice me on what to do. I will be very greatful.
    Edited by: kagara on Aug 27, 2008 12:27 PM

    With POP3 you have no choice but to download the messages and sort them in the client.
    The POP3 protocol simply doesn't provide a "sort" option.
    With IMAP, some IMAP servers support a "SORT" extension, although JavaMail doesn't
    support it yet.

  • Javamail api and Microsoft Exchange

    Hi there,
    I wonder if there are different settings for the javamail (SMTP, Authentication) when the user is using Micorsoft Exchange.
    The problem is that my user doesn't know what is his SMTP (I usually ask them to go to MS Outlook to figure it out) but since he is using the exchange software how can I tell what is the SMTP?
    are there different setttings for the javamail api in this case?
    thanks
    peter

    P_Primrose and Others,
    I too am having the same issues. At my work i have administrative access to our MS Exchange server and have noticed that the server can be set to use OR block access via SMTP, POP or IMAP. Also the type of connection can also be set, Encrypted connections or non-encrypted connections.
    Now i my instance I have noted that we have SMTP blocked, therefore no good and i have to swap to IMAP. Yuck. But my problem is that if my application is going to be developed to be used across all environments, will i run into the same problems when using other mail servers, such as Unix servers, etc.
    My question to the world is how can you test a connection to a mail server and find out what it's requirements are??? Is there a way to get the settings from the client's system settings (Regedit)??? If this can be done then it's just a matter of building a routine to mirror and set those variables for your JavaMail.

  • JavaMail API on JDK 1.6

    After going through README of JavaMail 1.4, i realised that it is not tested on JDK 1.6.
    Snippet from README
    The JavaMail API supports JDK 1.4 or higher. Note that we have
    currently tested this implementation only with JDK 1.4 and 1.5.
    I have few queries.
    Am i using wrong JavaMail version?
    If not then, has anybody tested/usedJavaMail 1.4 with JDK 1.6?
    Any issues faced?

    JDK 1.6 was release long after JavaMail 1.4 was released, which would make
    it hard to test JavaMail 1.4 on JDK 1.6. Since the release of JDK 1.6 I've used
    JavaMail 1.4 on JDK 1.6 with no problems. Note that the JavaBeans Activation
    Framework (JAF, aka activation.jar) is included in JDK 1.6.

  • Javamail API not reporting timeout

    Hi,
    I'm writing a POP3 application which pulls mails
    from a mail server processes them and then deletes
    them from the server.
    Occasionally the processing takes a while and the connection
    with the mailserver may timeout. This is fine because if I know
    its timed out, I could reconnect and find the mail and delete it.
    However what is happening is that the connection is timing out but the javamail api gives me no indication of this. The folder and store objects both report that they are open. Even if I use a connectionListener it tells me nothing.
    Now even this might not be a problem if the next oeration where to fail, as the same thing occurs in the transport object, however when I attempt to send it fails and closes the transport.
    However with the store I mark a message as deleted and then close, and it gives no exceptions letting me think I have successfully deleted a message, whereas in reality the underlying socket connection was closed and the message is still on the server.
    I have tried this several times looking at both the debug output on the mail server and from the javamail api.
    Is this a bug I should report or is there something I'm missing
    It seems pretty bad that javamail allows me to delete a message on a connection that is closed and not throw an exception.
    All ideas/suggestions welcome?
    Failing this does anyone know how to get the javamail api to send a NOOP
    command to keep the connection open.
    -vinnie

    I have been setting my timeouts manually.
    Properties props = System.getProperties();
    props.put("mail.imap.timeout",timeoutVal);
    props.put("mail.imap.connectiontimeout",timeoutVal);
    Session session = Session.getInstance(props,null);
    mail.pop3.timeout and mail.pop3.connectiontimeout are what you would want to use. Something else you might want to try is doing a Folder.getMessageCount() or some other low overhead transaction to keep the connection alive.

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

  • Getting exceptions while sending mail using javamail api

    Hi to all
    I am developing an application of sending a mail using JavaMail api. My program is below:
    quote:
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    public class sms
    public static void main(String args[])
    try
    String strstrsmtserver="smtp.bol.net.in";
    String strto="[email protected]";
    String strfrom="[email protected]";
    String strsubject="Hello";
    String bodytext="This is my first java mail program";
    sms s=new sms();
    s.send(strstrsmtserver,strto,strfrom,strsubject,bodytext);
    catch(Exception e)
    System.out.println("usage:java sms"+"strstrsmtpserver tosddress fromaddress subjecttext bodyText");
    System.exit(0);
    public void send(String strsmtpserver,String strto,String strfrom ,String strsubject,String bodytext)
    try
    java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    Properties p=new Properties(System.getProperties());
    if(strsmtpserver!=null)
    p.put("mail.transport.protocol","smtp");
    p.put("mail.smtp.host","[email protected]");
    p.put("mail.smtp.port","25");
    Session session=Session.getDefaultInstance(p);
    Message msg=new MimeMessage(session);
    Transport trans = session.getTransport("smtp");
    trans.connect("smtp.bol.net.in","[email protected]","1234563757");
    msg.setFrom(new InternetAddress(strfrom));
    msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(strto,false));
    msg.setSubject(strsubject);
    msg.setText(bodytext);
    msg.setHeader("X-Mailer","mtnlmail");
    msg.setSentDate(new Date());
    Transport.send(msg);
    System.out.println("Message sent OK.");
    catch(Exception ex)
    System.out.println("here is error");
    ex.printStackTrace();
    It compiles fine but showing exceptions at run time.Please help me to remove these exceptions.I am new to this JavaMail and it is my first program of javamail.Please also tell me how to use smtp server.I am using MTNL 's internet connection having smtp.bol.net.in server.
    exceptions are:
    Here is exception
    quote:
    Javax.mail.MessagingException:Could not connect to SMTP host : smtp.bol.net.in, port :25;
    Nested exception is :
    Java.net.ConnectException:Connection refused: connect
    At com.sun.mail.smtp.SMTPTransport.openServer<SMTPTransport.java:1227>
    At com.sun.mail.smtp.SMTPTransport.protocolConnect<SMTPTransport.java:322>
    At javax.mail.Service .connect(Service.java:236>
    At javax.mail.Service.connect<Service.java:137>
    At sms.send<sms.java:77>
    At sms.main<sms.java:24>

    Did you find the JavaMail FAQ?
    You should talk to your ISP to get the details for connecting to your server.
    In this case I suspect your server wants you to make the connection on the
    secure port. The FAQ has examples of how to do this for GMail and Yahoo
    mail, which work similarly. By changing the host name, these same examples
    will likely work for you.

  • Help - PDF Attachment Problem

    Hi,
    Receently, some of our users experienced pdf attachment problem. The user sent a 4mb pdf attachment but after the mail was sent out it only showed 4k in sent item. When the recipient received the e-mail the attachment also showed 4kb and it can't be opend too. These users are using Outlook 2000 and our Exchange server is 2000 Enterprise.
    Thanks for the help,
    JY

    Hi Suresh,
    I just tried this thing in my systtem and it is working... BADI is trigerred everytime there is a change in the PO... even when you release there is a change in the PO so this BADI will be triggerred....
    I suggest you should implement BADI in your dev system and place a break point in the POST method...
    After that create a PO and release it using ME29N... thereafter when you save the PO... this method will trigger and you will have access to PO details...
    PS: Remember this BADI wont work for transaction ME29...
    Regards
    Gautam

  • Pdf attachment problems on osx lion

    Hello
    i was wondering if apple has fixed the pdf attachment problem seen on other iOS' such as 7.1.  I get the same error (blank pdf file, white screen), however, it doesn't happen all the time. 
    any explanations and comments would be greatly appreciated!

    OS 7 or IOS 7?
    If IOS 7, try the iPad community.
    iPad Community

  • Any changes in JavaMail Api

    Hi
    Is their any change in javamail api with the release of SE 6.
    When was javamail api last updated or changed.
    null

    JavaMail will work fine on Java SE 6.
    JavaMail was last updated about a year ago.

  • X.400 instead of SMTP Protocol and Javamail API

    We have developed a workflow application on Domino 5.0.7. The SmartHost is "MS Exchange Server", because the application will only be accessed by browsers, we are using javaagent to send the email notifications. Due to some domain restrictions on MS Exhchange servers we have implemented Javamail API on the domino server, and it worked fine (I mean the messages were received by the Exchange Clients, using the SMTP addresses like [email protected]). As we dont have available SMTP addresses for all end users in the company we need to use the X.400 addresses. Is there anyone, can help guide about either the avaiability of any X.400 javamail api, or how to use mapi etc? I know it is little bit challenging, but we are struck. thanks

    Currently, the latest version of the JavaMail 1.2 API, X.400 transport protocol is not supported yet. Only the transport SMTP - a message Transport protocol, for sending messages to a server, is supported.
    Allen Lai
    SUN Developer Technical Support

Maybe you are looking for

  • Activity/step in the workflow has a blinking red outline

    Symptom Activity/step blinks red in the diagram, and the workflow goes to the Paused state (default behavior.) The workflow Failed flag is set to Yes (true) which can be seen in an Explorer folder or view containing workflows or in the Home page Inst

  • XP system DVD/CD RW burner no longer "sees" DVDs

    After installing itunes on my system my DVD/CD Burner "Liteon 1693S" sees only CD roms and will not recognize a Blank DVD. When a blank DVD is placed in the drive it identifies it as a CD Rom. Any suggestions? I already tried updating the Firmware fo

  • Lots of duplicate songs-anyway to delete a bunch quickly

    I kind of messed up my library when I was attempting to set up separate libraries. I have straightened it out, however, now I have 1-2 duplicates of almost all of my songs. I was wondering if there was an action that would delete all of the duplicate

  • Update flash player several time in a few hours when on facebook

    Hello,    I am having to download flash player 10.2.152.32 daily . My browser is eithe window 7 or 8.  Often several times a day. I may only be logged on for 2-4 hours.  I have  windows Vista 2007/ 2 gb memory/ 32 bite.  I play  the games on facebook

  • Problem with viewing netflix

    I just downloaded beta 7 and whenever I try to view Netflix, I get a message that says "Thanks for installing. Once installation is complete please restart your browser to watch this movie." I've reinstalled Silverlight, recalibrated the plugins, rei