Help me IN JAVA MAIL

HI TO ALL......
I AM NEW TO THIS FIELD....I AM TRYING TO SEND EMAIL THROUGH JAVA MAIL FUNCTION......,FIRST I AM FETCHING THE MAIL ADDRESS FROM DATA BASE.....I WANT TO SEND MAIL TO THOSE ADDRESS......HERE I M LITTLE BIT CONFUSED....PLZ HELP ME....BELOW IS THE CODE.........
THIS FOR SEARCHING THE MAIL IDS......(SearchEmail .java)
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class SearchEmail extends HttpServlet {
public String s1;
public String username="root";
public String passWord="";
public String url="jdbc:mysql://192.168.0.7:3306/ias";
private String SUB_NO="";
private String ST_DT="";
private String EMAIL="";
public void init() {
try {
Class.forName("sun.mysql.Jdbc.Driver");
System.out.println("JDBC driver loaded");
catch (ClassNotFoundException e) {
System.out.println(e.toString());
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
sendPageHeader(response);
sendSearchForm(response);
sendPageFooter(response);
/**Process the HTTP Post request*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ST_DT = request.getParameter("ST_DT");
sendPageHeader(response);
sendSearchForm(response);
sendSearchResult(response);
sendPageFooter(response);
public void sendSearchResult(HttpServletResponse response)
throws IOException {
PrintWriter out = response.getWriter();
try {
Connection con = DriverManager.getConnection(url,username,passWord);
System.out.println("got connection");
Statement s = con.createStatement();
String sql= "SELECT EMAIL " + "FROM temp "+
"WHERE ST_DT='" + ST_DT + "' AND EMAIL!='" + null + "'";
ResultSet rs = s.executeQuery(sql);
StringBuffer sb = new StringBuffer(100);
while (rs.next()) {
String SUB_NO = rs.getString(1);
s1 =sb.append( rs.getString(1)).append(",").toString();
out.println("<TABLE border='1'>");
out.println("<TR>");
out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' ></TD>");
out.println("</TR>");
out.println("<TR>");
out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' [email protected] ></TD>");
out.println("</TR>");
out.println("</TR>");
out.println("<TD>SUBJECT</TD><TD><INPUT TYPE=TEXT SIZE='50' NAME=SUBJECT></TD>");
out.println("</TR>");
out.println("<TR>");
out.println("<TD>MESSAGE </TD><td><textarea cols='70' rows='20' name='MESSAGE'>");
out.println("C.Vedamurthy senior");
out.println("Administrative Assistant");
out.println("Indian Academy of Sciences");
out.println("C.V.Raman Avenue,Near Mekhri Circle");
out.println("Post Box No 8005,sadashivanagar'");
out.println("bangalore 560080");
out.println("office no 23612546,23611034,23612943 extn 207 ");
out.println("res 23431357;Fax 23616094;");
out.println("</textarea></td>");
out.println("</TR>");
out.println("<table align='center'>");
out.println("<TR>");
out.println("<form action='mailservlet' method='post' name='myform'>");
out.println("<CENTER> <TD><INPUT TYPE='SUBMIT' VALUE='send'></INPUT></TD></CENTER>");
out.println("</form>");
out.println("</TR>");
out.println("</TABLE>");
rs.close();
s.close();
con.close();
catch (SQLException e) {
catch (Exception e) {
out.println("</TABLE>");
* Send the HTML page header, including the title
* and the <BODY> tag
private void sendPageHeader(HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Displaying Selected Record(s)</TITLE>");
out.println("</HEAD>");
out.println("<BODY BGCOLOR=#FFE4C4>");
out.println("<CENTER>");
* Send the HTML page footer, i.e. the </BODY>
* and the </HTML>
private void sendPageFooter(HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("</CENTER>");
out.println("</BODY>");
out.println("</HTML>");
/**Send the form where the user can type in
* the details for a new user
private void sendSearchForm(HttpServletResponse response)
throws IOException {
PrintWriter out = response.getWriter();
out.println("<BR><H2>Search</H2>");
out.println("<BR>");
out.println("<BR><FORM METHOD=POST>");
out.print("START DATE: <INPUT TYPE=TEXT Name=ST_DT");
out.print(" VALUE=\"" + ST_DT + "\"");
out.println(">");
out.println("<BOTTOM>");
out.println("<TABLE ALIGN='CENTER'>");
out.println("<INPUT TYPE=SUBMIT VALUE=submit>");
out.println("</TABLE>");
out.println("</FORM>");
THIS IS JAVA MAIL FUNCTION.........(mailservlet .java)
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*; // important
import javax.mail.event.*; // important
import java.net.*;
import java.util.*;
import javax.mail.MessagingException;
public class mailservlet extends HttpServlet
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
PrintWriter out=response.getWriter();
response.setContentType("text/html");
try
Properties props=new Properties();
props.put("mail.smtp.host","localhost"); // 'localhost' for testing
Session session1 = Session.getDefaultInstance(props,null);
String s1 = request.getParameter("FROM"); //sender (from)
String s2 = request.getParameter("EMAIL");
String s3 = request.getParameter("SUBJECT");
String s4 = request.getParameter("MESSAGE");
Message message =new MimeMessage(session1);
message.setFrom(new InternetAddress(s1));
message.setRecipients
(Message.RecipientType.TO,InternetAddress.parse(s2,false));
message.setSubject(s3);
message.setText(s4);
Transport.send(message);
out.println("mail has been sent");
catch(Exception ex)
out.println("COULD NOT SEND EMAIL.....");
plz help me its very urgent ........

out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' ></TD>");
out.println("</TR>");
out.println("<TR>");
out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE=[email protected] ></TD>");
You didn't put names to those fields above:
out.println("<TD>TO</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='"+ s1 +"' name ='EMAIL'></TD>");
out.println("</TR>");
out.println("<TR>");
out.println("<TD>FROM</TD><TD><INPUT TYPE=TEXT SIZE='50' VALUE='[email protected]'  name='FROM'></TD>");also try:
catch(Exception ex)
out.println("COULD NOT SEND EMAIL.....");
ex.printStackTrace();
}to know what is exactly the error.

Similar Messages

  • Help needed for java mail services

    Hi All,
    I am new to JMS.Can u help me in getting some gud tutorial?
    Any help is appreciated.
    Thanx in advance....

    Hi Praveen,
    Go thru Google to get tuto.

  • Java mail and jsp -HELP!! HELP!!

    Hi all
    I have a simple email module with a jsp page and a html page I am trying to connect to a yahoo smtp server and send a mail from the webpage to the smtp server - I am getting an Authentication required error.
    error ##
    org.apache.jasper.JasperException: Sending failed;
    nested exception is:
         class javax.mail.MessagingException: 530 authentication required - for help go to http://help.yahoo.com/help/us/sbc/dsl/mail/pop/pop-11.html
    Can anyonne tell me how to use a simple smtp email facility
    how to use an authenticator in the jsp
    ciao
    laodingdockjavaguy

    It's required that you authentificate yourself at the smpt server
    The following snipplet sends a msg using the smtp protocol.
    Transport tr = session.getTransport("smtp");
    tr.connect(smtphost, username, password);
    msg.saveChanges();     // don't forget this
    tr.sendMessage(msg, msg.getAllRecipients());
    tr.close();If this still fails You can also try to set the property mail.smtp.auth to true.
    mail.smtp.auth      boolean      If true, attempt to authenticate the user using the AUTH command. Defaults to false.see also http://java.sun.com/products/javamail/1.3/docs/javadocs/com/sun/mail/smtp/package-summary.html
    for a complete description of the properties supported by the smpt transport.
    hope it helps

  • Java Mail Project HELP Required....URGENT PLZ HELP!!!

    hello there!!
    i took up a pjct for my engineering on java mail..got the code..and i thought that ill analyse it...the code is submitting the mail to the smtp server but after dat its failing to deliver to the client..as i can see this error in the logs on SMTP server...can anyone help me out in analysing this code!!!
    plz help, exams are near...(am new to java)
    //java FINAL!
    import javax.swing.*;
    import java.net.URL;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class EmailProg extends JPanel implements ActionListener {
    protected JTextArea textArea;
    protected String newline = "\n";
    static final private String composemail = "compose";
    static final private String sendmail = "send";
    static final private String about = "about";
    static final private String submit = "submit";
    static final private String exit = "exit";
    JLabel lSubmit = new JLabel("Submit");
    JButton subbutton = new JButton();
    JTextArea emailfrom = new JTextArea(1,1);
    JTextArea emailto = new JTextArea(1, 1);
    JTextArea emailsubject = new JTextArea(1, 1);
    JTextArea emailmessage = new JTextArea(25, 1);
    //------BAG LAYOUT
    JLabel lFrom = new JLabel("From:");
    JTextField cFrom = new JTextField(32);
    JLabel lTo = new JLabel("To:");
    JTextField cTo = new JTextField(32);
    JFrame frame2 = new JFrame("Compose New");
    JLabel lSubject = new JLabel("Subject");
    JTextField cSubject = new JTextField(32);
    JLabel lMessage = new JLabel("Body");
    JTextArea cMessage = new JTextArea(5,32);
    //====================================
    public EmailProg() {
    super(new BorderLayout());
    //Create the toolbar.
    JToolBar toolBar = new JToolBar();
    addButtons(toolBar);
    //Create the text area used for output. Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    textArea.setText("Welcome to Jeff's email program! With this program you can compose and send emails. I hope I get a good grade on thise, and marine world finds a good use for it :-D:-D (implements really just testing the scroller!!!)");
    JScrollPane scrollPane = new JScrollPane(textArea);
    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 110));
    add(toolBar, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    //==================================
    protected void addButtons(JToolBar toolBar) {
    JButton button = null;
    //first button
    button = makeNavigationButton("/toolbarButtonGraphics/general/ComposeMail24.gif", composemail ,"Compose new Email", "compose new");
    toolBar.add(button);
    //second button
    button = makeNavigationButton("toolbarButtonGraphics/general/SendMail24.gif", sendmail,"Send The Mail","send");
    toolBar.add(button);
    //third button
    button = makeNavigationButton("toolbarButtonGraphics/general/About24.gif", about,"About","About");
    toolBar.add(button);
    //exit button
    button = makeNavigationButton("toolbarButtonGraphics/general/Stop24.gif", exit, "Exit", "Exit");
    toolBar.add(button);
    //===================================
    protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {
    //Look for the image.
    String imgLocation = imageName;
    URL imageURL = EmailProg.class.getResource(imgLocation);
    //Create and initialize the button.
    JButton button = new JButton();
    button.setActionCommand(actionCommand);
    button.setToolTipText(toolTipText);
    button.addActionListener(this);
    if (imageURL != null) {                      //image found
    button.setIcon(new ImageIcon(imageURL));
    } else {                                     //no image found
    button.setText(altText);
    System.err.println("Resource not found: "+ imgLocation);
    return button;
    //=============================
    public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    String description = null;
    // Handle each button.
    if (exit.equals(cmd)){
    textArea.setText("");
    description = "EXITING";
    System.exit(0);
    if (composemail.equals(cmd)) { //first button clicked
    textArea.setText("");
    description = "Write new mail.";
    composeWindow();
    } else if (sendmail.equals(cmd)) { // second button clicked
    textArea.setText("");
    description = "This button does'nt do anything yet :x";
    } else if (about.equals(cmd)) { // third button clicked
    textArea.setText("");
    description = "About this program. (See pop-up)";
    coolWindow();
    else if (submit.equals(cmd))
    if (cFrom.getText().equals("")||cTo.getText().equals("")||cSubject.getText().equals("")||cMessage.getText().equals(""))
    textArea.setText("One or more of the fields was not filled in.");
    else{
    try {
    String smtpServer="serverhere";
    String to=cTo.getText();
    String from=cFrom.getText();
    String subject=cSubject.getText();
    String body=cMessage.getText();
    send(smtpServer, to, from, subject, body);
    textArea.setText("");
    description = "Mail Sent.";
    JOptionPane.showMessageDialog(null, "Message Sent.");
    catch (Exception ex)
    System.out.println("Usage: java com.lotontech.mail.SimpleSender"
    +" smtpServer toAddress fromAddress subjectText bodyText");
    //CLOSE THE FRAME2 WINDOW IIIIIIIIFFFFFFF SENDING IS SUCCESSFUL!!
    }//end of else during send
    }//end of if of submit
    displayResult(description);
    //============================
    protected void displayResult(String actionDescription) {
    textArea.append(actionDescription + newline);
    //=============================
    public void coolWindow() {
    JFrame frame = new JFrame("About");
    JTextArea filecontents = new JTextArea();
    filecontents.setText("Use the tool bar to compose\n compose new emails, in which you can\n send to anyone on the\n srvhs email server. \n Fill in all the blanks before pressing send. If you dont\n you will receive an error! \n For more information about this program click on the\n information button.");
    frame.getContentPane().add(filecontents, BorderLayout.CENTER);
    frame.pack();
    frame.setResizable(false);
    frame.setSize(300,200);
    frame.setVisible(true);
    //===============================
    public void composeWindow() {
    frame2.getContentPane().setLayout(new GridBagLayout());
    frame2.setResizable(false);
    frame2.setSize(600,500);
    frame2.setVisible(true);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(5, 10, 5, 10);
    cMessage.setLineWrap(true);
    subbutton = makeNavigationButton("toolbarButtonGraphics/general/SendMail24.gif", submit,"submit","submit");
    addRow(gbc, lFrom, cFrom);
    addRow(gbc, lTo, cTo);
    addRow(gbc, lSubject, cSubject);
    addRow(gbc, lMessage, cMessage);
    addRow(gbc, lSubmit, subbutton);
    //===============================
    private void addRow(GridBagConstraints gbc, Component left, Component right) {
    gbc.gridx = GridBagConstraints.RELATIVE;
    gbc.gridy = GridBagConstraints.RELATIVE;
    gbc.gridheight = 1;
    gbc.gridwidth = 1;
    gbc.anchor = GridBagConstraints.EAST;
    frame2.getContentPane().add(left, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.WEST;
    frame2.getContentPane().add(right, gbc);
    frame2.pack();
    //=======================
    public static void send(String smtpServer, String to, String from, String subject, String body) {
    try {
    Properties props = System.getProperties();
    props.put("localhost", smtpServer);
    Session session = Session.getDefaultInstance(props, null);
    System.out.println(smtpServer);
    // -- Create a new message --
    Message msg = new MimeMessage(session);
    // -- Set the FROM and TO fields --
    msg.setFrom(new InternetAddress(from));
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
    // -- We could include CC recipients too --
    // if (cc != null)
    // msg.setRecipients(Message.RecipientType.CC
    // ,InternetAddress.parse(cc, false));
    // -- Set the subject and body text --
    msg.setSubject(subject);
    msg.setText(body);
    // -- Set some other header information --
    msg.setHeader("X-Mailer", "LOTONtechEmail");
    msg.setSentDate(new Date());
    // -- Send the message --
    Transport.send(msg);
    System.out.println("Message sent OK.");
    catch (Exception ex)
    ex.printStackTrace();
    public static void main(String[] args) {
    JFrame frame = new JFrame("EmailProg");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    EmailProg newContentPane = new EmailProg();
    newContentPane.setOpaque(true);
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

    The code to retrieve the messages from SMTP
    finally all working fine...
    thanx guys!!!
    package EmailProg;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.io.*;
      * A simple email receiver class.
    public class SimpleReceiver
        * Main method to receive messages from the mail server specified
        * as command line arguments.
      public static void main(String args[])
        try
          String popServer=args[0];
          String popUser=args[1];
          String popPassword=args[2];
          receive(popServer, popUser, popPassword);
        catch (Exception ex)
          System.out.println("Usage: java com.mail.SimpleReceiver" +" popServer popUser popPassword");
        System.exit(0);
         * "receive" method to fetch messages and process them.
       public static void receive(String popServer, String popUser, String popPassword)
         Store store=null;
         Folder folder=null;
         try
           // -- Get hold of the default session --
           Properties props = System.getProperties();
           Session session = Session.getDefaultInstance(props, null);
           // -- Get hold of a POP3 message store, and connect to it --
           store = session.getStore("pop3");
           store.connect(popServer, popUser, popPassword);
           // -- Try to get hold of the default folder --
           folder = store.getDefaultFolder();
           if (folder == null) throw new Exception("No default folder");
           // -- ...and its INBOX --
           folder = folder.getFolder("INBOX");
           if (folder == null) throw new Exception("No POP3 INBOX");
           // -- Open the folder for read only --
           folder.open(Folder.READ_ONLY);
           // -- Get the message wrappers and process them --
           Message[] msgs = folder.getMessages();
           for (int msgNum = 0; msgNum < msgs.length; msgNum++)
             System.out.println(msgs[msgNum]);
         catch (Exception ex)
           ex.printStackTrace();
         finally
           // -- Close down nicely --
           try
             if (folder!=null) folder.close(false);
             if (store!=null) store.close();
           catch (Exception ex2) {ex2.printStackTrace();
      }

  • Java Mail,SMTP server not starting,help required urgently

    Hi i have been working on java mail .Yesterday it was working ok but today suddenely i am getting this thing.its not starting the smtp server i guess,just exiting and get the command prompt ..dont know what to do.help required how to go about this error
    am pasting the debug information.please check and let me know
    the compilation ,smtp server and others are all valid
    thanks
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    C:\Documents and Settings\Pavan>cd C:\Program Files\Java\jdk1.5.0_07\bin
    C:\Program Files\Java\jdk1.5.0_07\bin>javac jdbcExample3.java
    C:\Program Files\Java\jdk1.5.0_07\bin>java jdbcExample3 smtpserver address
    DEBUG: JavaMail version 1.4ea
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_07\jre\lib\
    javamail.providers (The system cannot find the file specified)
    DEBUG: !anyLoaded
    DEBUG: not loading resource: /META-INF/javamail.providers
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax
    .mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsyste
    ms, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com
    .sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLSt
    ore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsyst
    ems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.su
    n.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=jav
    ax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc],
    com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP
    3Store,Sun Microsystems, Inc]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.
    sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STOR
    E,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Prov
    ider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc],
    pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems
    , Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
    Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.S
    MTPTransport,Sun Microsystems, Inc]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: !anyLoaded
    DEBUG: not loading resource: /META-INF/javamail.address.map
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_07\jre\lib\
    javamail.address.map (The system cannot find the file specified)
    C:\Program Files\Java\jdk1.5.0_07\bin>

    The debug output doesn't show an obvious problem. You're
    going to have to actually debug your program. A debugger
    might be helpful.

  • Urgent help on java mail

    Hi,
    I have one prob with java mail .. How do i display file content in email ...
    When i pass content as String(suppose hello) it displays hello in email ....How do i display file content in html form when user opens his email .....
    Any help on this i will appriciate ..........
    Thanks.

    Hi,
    I have one jsp file and this file includes some include files ......
    How do i send this jsp file as body of email using java mail ................
    I did this by hot coding the tags and content ... i have to read from jps file and this file include some images ...........
    Here is my code ... Please can any one help me ....
    import java.io.*;
    import java.util.Properties;
    import java.util.Date;
    import javax.mail.*;
    import javax.activation.*;
    import javax.mail.internet.*;
    public class sendhtml {
    public static void sendMess(String[] argv) {
    String to, subject = "hello", from = null,
    cc = null, bcc = null, url = null;
    String mailhost = "xx.xxx.xx.xx";
    String mailer = "sendhtml";
    String protocol = null, host = null, user = null, password = null;
    String record = null; // name of folder in which to record mail
    boolean debug = false;
    try {  
    to="[email protected]";
    Properties props = System.getProperties();
    // could use Session.getTransport() and Transport.connect()
    // assume we're using SMTP
    if (mailhost != null)
    props.put("mail.smtp.host", mailhost);
    // Get a Session object
    Session session = Session.getDefaultInstance(props, null);
    if (debug)
    session.setDebug(true);
    // construct the message
    Message msg = new MimeMessage(session);
    if (from != null)
    msg.setFrom(new InternetAddress(from));
    else
    msg.setFrom();
    msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(to, false));
    if (cc != null)
    msg.setRecipients(Message.RecipientType.CC,
    InternetAddress.parse(cc, false));
    if (bcc != null)
    msg.setRecipients(Message.RecipientType.BCC,
    InternetAddress.parse(bcc, false));
    msg.setSubject(subject);
    MimeMultipart mp = new MimeMultipart();
    mp.setSubType("related");
    MimeBodyPart mbp1= new MimeBodyPart();
    String html =
    "<html>"+
    "<head><title></title></head>"+
    "<body>"+
    "<b> see the following jpg : it is a car! !!!!!</b><br>"+
    "<a href=a.jsp>hello</a><br>"+
    "<img src=cid:123 >"+
    "<IMG SRC=cid:23 ><br>"+
    "<b> end of jpg</b>"+
    "<table><tr><td>"+
    "Every couple days for the next four weeks, we will send you new"+
    "can successfully sell your home.<br><br></td></tr>"+
    "<tr><td>"+
    "<p class=\"letter\">"+
         "saleMail Topics are: <br><br>"+
         "<ol class=\"letter\">"+
    "<li><b>Advertising Your Home: Part 2</b></li>"+
    "<li><b> Possibilities</b></li>"+
         "<li><b>Where Do You Go From Here?</b></li>"+
    "</ol>"+
    "<br><br></p></td></tr></table>"+
    "</body>"+
    "</html>";
    mbp1.setContent(html,"text/html");
    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource("/usr/local/images/dualsign.gif");
    mbp2.setFileName(fds.getName());
    mbp2.setText("This is a beautiful car !");
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setHeader("Content-ID","23");
    FileDataSource fds1 = new FileDataSource("/usr/local/images/logo.gif");
    mbp2.setFileName(fds1.getName());
    mbp2.setText("This is a beautiful car !");
    mbp2.setDataHandler(new DataHandler(fds1));
    mbp2.setHeader("Content-ID","123");
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    msg.setContent(mp);
    msg.setSentDate(new Date());
    Transport.send(msg);
    System.out.println(mp.getCount());
    System.out.println("\nMail was sent successfully.");
    } catch (Exception e) {
    e.printStackTrace();

  • Problems while sending mail using java mail..help...

    Hello all,
    I am new to Java Mail...
    Below is my first program...
    Can anybody tell what's wrong in it..??
    Thanks in advance....
    ------------------------------------------------------start--------------------
    package test;
    import java.util.Properties;
    import javax.mail.Address;
    import javax.mail.Authenticator;
    import javax.mail.MessagingException;
    import javax.mail.NoSuchProviderException;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.Message.RecipientType;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    public class Send
         public Send()
         public void send()
              java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              Properties props=new Properties();
              props.put("mail.transport.protocol", "smtp");
              props.put("mail.smtp.host","smtp.gmail.com");
              props.put("mail.smtp.port","25");
              props.put("mail.smtp.auth","true");
              Session session=Session.getDefaultInstance(props,new MyAuthenticator());
              session.setDebug(true);
              MimeMessage message=new MimeMessage(session);
              try
                   message.setContent("Hello ...","text/plain");
                   message.setSubject("Test mail...plz don't ignore..");
                   Address to=new InternetAddress("[email protected]");
                   Address from=new InternetAddress("[email protected]");
                   Address replyTo=new InternetAddress("[email protected]");
                   message.setFrom(from);
                   message.setReplyTo(new Address[]{replyTo});
                   message.setRecipient(RecipientType.TO,to);               
                   Transport.send(message);
              } catch (AddressException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (NoSuchProviderException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (MessagingException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public static void main(String[] args)
              new Send().send();          
         class MyAuthenticator extends Authenticator
              MyAuthenticator()
                   super();
              protected PasswordAuthentication getPasswordAuthentication()
                   return new PasswordAuthentication("[email protected]", "*******");
    --------------------------------------------end--------------
    here is the output.....
    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
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
    220 mx.gmail.com ESMTP 16sm2443823wrl
    DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
    EHLO jijo
    250-mx.gmail.com at your service
    250-SIZE 20971520
    250-8BITMIME
    250-STARTTLS
    250 ENHANCEDSTATUSCODES
    DEBUG SMTP: Found extension "SIZE", arg "20971520"
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: Found extension "STARTTLS", arg ""
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    530 5.7.0 Must issue a STARTTLS command first
    com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
         at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at test.Send.send(Send.java:50)
         at test.Send.main(Send.java:68)
    QUIT
    com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
         at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at test.Send.send(Send.java:50)
         at test.Send.main(Send.java:68)
    Can any body help me..??
    Thanks and Regards
    Jijo vincent

    Hi All,
    I am new to javax.mail.
    I have attached my code and also error here...
    can anyone help to resolve the error?
    Code:
    public class MailExample {
         public static void main(String args[]) {
              try {
              String host = "localhost"; //args[0];
              String from = "[email protected]"; //args[1];
    //          String to = "[email protected]";//args[2];
              String to = "[email protected]";//args[2];
              java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              // Get system properties
              Properties props = System.getProperties();
              // Setup mail server
              props.put("mail.smtp.host", host);
              props.put("mail.smtp.starttls.enable","true");
              //props.put("mail.smtp.auth","true");
              // Get session
              Session session = Session.getDefaultInstance(props, null);
              session.setDebug(true);
              // Define message
              MimeMessage message = new MimeMessage(session);
              // Set the from address
              message.setFrom(new InternetAddress(from));
              // Set the to address
              message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
              // Set the subject
              message.setSubject("Hello JavaMail");
              // Set the content
              message.setText("Welcome to JavaMail");
              // Send message
              Transport.send(message);
              catch(AddressException ae){
                   ae.printStackTrace();
              }catch (MessagingException e)
    //               TODO Auto-generated catch block
                   e.printStackTrace();
    Error:
    DEBUG: setDebug: JavaMail version 1.3.3ea
    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 "localhost", port 25, isSSL false
    220 localhost
    DEBUG SMTP: connected to host "localhost", port: 25
    EHLO HDCHCTDAM33726
    250-localhost
    250 HELP
    DEBUG SMTP: Found extension "HELP", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<[email protected]>
    250 [email protected] Address Okay
    RCPT TO:<[email protected]>
    250 [email protected] Address Okay
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP: [email protected]
    DATA
    354 Start mail input; end with <CRLF>.<CRLF>
    Message-ID: <10736847.01125315340863.JavaMail.sangeetham@HDCHCTDAM33726>
    From: [email protected]
    To: [email protected]
    Subject: Hello JavaMail
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Welcome to JavaMail
    com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
         at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)550 Invalid recipient: [email protected]
    com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
         at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
         at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
         at javax.mail.Transport.send0(Transport.java:151)
         at javax.mail.Transport.send(Transport.java:80)
         at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)
    QUIT

  • Java Mail Program - Please Help!

    Hi everyone, I am new to Java (been learnig for about 6 months) and I was hoping you could help me.
    I would like to write a program to be able to send and receive email (a basic version of outlook express), the prblem is that i have no idea on how to start such a program as i have only written programs such as calculators before.
    I was hoping someone could tell me how to begin such a challenging program, which java package is best to create such a program, Jbuilder or the normal javac compiler.
    Thanks everyone for your help

    See the Java mail API for more details (javax.mail if I remember well). This can be found at:
    http://java.sun.com/products/javamail/index.html
    Hope it helps,
    Stephane

  • About Java Mail Api ...Please help..?

    Hi,
    I am sending email thruogh java mail api. Email has sent but in console, It is in debug mode as this is the messages:
    DEBUG: JavaMail version 1.4.1*
    DEBUG: not loading file: C:\Program Files\Java\jdk1.6.0_10\jre\lib\javamail.providers*
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_10\jre\lib\javamail.providers (The system cannot find the file specified)*
    DEBUG: !anyLoaded*
    DEBUG: not loading resource: /META-INF/javamail.providers*
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers*
    DEBUG: Tables of loaded providers*
    +DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}+*
    +DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}+*
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map*
    DEBUG: !anyLoaded*
    DEBUG: not loading resource: /META-INF/javamail.address.map*
    DEBUG: not loading file: C:\Program Files\Java\jdk1.6.0_10\jre\lib\javamail.address.map*
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_10\jre\lib\javamail.address.map (The system cannot find the file specified)*
    it is printing more statements. I just want to remove that can i ? I had tried session.setDebug(false). But still showing me debug messages. please tell me it is really urgent.
    thanks in advance.
    Manveer
    Edited by: Manveer-Singh on Feb 2, 2010 5:25 PM

    Remove the logger statement from your program,
    or
    Check your IDE is in debug mode
    or
    paste your code and tell what environment are you using.

  • Java Mail set up HELP

    I am trying to set up Java Mail, but am totally lost.
    I have no clue where i edit CLASSPATH, to let me use the mail api, i also read that i needed Java beans activation Network, but that is included in the most recent JDK update which i have.
    If i could just get a step by step on where to edit this that would be great.

    I don't know what JBA is.
    README.txt says:
      1. Unzip the javamail-1_4_1.zip archive. (you may have already done this)
      2. Set your CLASSPATH to include the "mail.jar" file obtained from
         the download, as well as the current directory.
         Assuming you unzipped javamail-1_4_1.zip in c:\download the
         following would work:
          set CLASSPATH=%CLASSPATH%;c:\download\javamail-1.4.1\mail.jar;.
        Also include the "activation.jar" file that you obtained from
        downloading the JavaBeans Activation Framework, in your CLASSPATH.
          set CLASSPATH=%CLASSPATH%;c:\download\activation\activation.jarWhich part of that was confusing?
    Yes, you can download it anywhere and unzip it
    anywhere, but wherever you put it, that's the
    path you have to use when you set CLASSPATH.
    Do you understand?
    Likewise, you have to download the JavaBeans
    Activation Framework, unzip the zip file (anywhere)
    and use the correct path name when setting
    CLASSPATH.
    If it's still not working for you, tell me exactly what
    you did and exactly what happened. Copy and
    paste the text from the command window if possible.

  • Help for java mail

    i want devloped java mail , what should i do

    Everything you need is on the JavaMail web page, which was referred to
    in the header to this forum. Did you see it?
    http://java.sun.com/products/javamail

  • Java mail api - sending mails to gmail account

    Hello
    I am using java mail api to send mails.when i send mails to gmail from ids which are not in gmail friends list, most of the mails are going to spam.Ofcourse, some of them go to inbox.I tried in lot of ways to analyse the problem.But nothing could help. Can anyone plzz tell me how to avoid mails going to spam in gmail, using java mail api?
    Thank you in advance,
    Regards,
    Aradhana
    Message was edited by:
    Aradhana

    am using the below code.
    Properties props = System.getProperties();
    //          Setup mail server
              props.put("mail.smtp.host", smtpHost);
              props.put("mail.smtp.port","25");
              props.put("mail.smtp.auth", isAuth);
         Authenticator auth = new UserAuthenticator();
    //          Get session
              Session s = Session.getDefaultInstance(props,auth);
    //          Define message
              Message m = new MimeMessage(s);
    //          setting message attributes
              try {
                   m.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
                   InternetAddress f_addr=new InternetAddress(from);
                   f_addr.setPersonal(personalName);
                   m.setFrom(f_addr);               
                   m.setSubject(subject);
                   m.setSentDate(new Date());
                   m.setContent(msg,"text/plain");
                   m.saveChanges();
    //               send message
                   Transport.send(m);
    Message was edited by:
    Aradhana

  • Can java mail be used for distributed exchange server?

    H,
    I am trying to connect to MS Exchange Server to read my mails using Java Mail API.
    I have a questions about using it with Exchange server.
    We have 6-7 exchange servers in our company and different users have mailboxes on different servers. My internet mail application will be used by everybody in the company.
    But while connecting to exchange server using java mail I can only cnnnect to one server and port. What happens when user mailbox is not on that server. How can I use javamail in this scenario where user mailboxes are on separate servers??
    Thanks
    [email protected]

    You said that you can connect to Exchange server my you help me with this because i cant connect to Exchange server, mayby you can post me a code example? Thanks

  • How can i access gmail's smtp server using java mail api

    i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
    if anybody can help me in this regard i m thnkful to him/her.
    thnks in advance.
    jogin desai

    Here's an example of using SSL + Authentication
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums

  • Error while sending mail when using Java Mail API

    Hi Experts,
    I am trying to execute a webdynpro application which uses the Java Mail API to send emails. The exception that I get on executing the application is :
    Sending failed;  nested exception is: javax.mail.SendFailedException: Invalid Addresses;  nested exception is: javax.mail.SendFailedException: 550 5.7.1 Unable to relay for [email protected]
    Can anybody please help me sort out the issue.
    Regards
    Abdullah

    Hi,
    Usually one get this error if the SMTP server is configured not to relay mails (a security measure) or the SMTP server need the mail to be sent from a trusted IP or with proper authentication. Some SMTP servers are configured to block junk mails.
    Pls check with your  mail server administrator.
    Regards

Maybe you are looking for