About javamail

hellow hi friend i have one doubt i am new in javamail so i have successfully compiled following javamail program
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class sendMail
sendMail()
public static void send(String smtpServer, String to, String from, String subject, String body)
try
Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);
// -- 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();
know i want to call this class in my jsp page so please tell me how and how to configure the xml file also i am using tomcat 6.0 ok please if u have solution please solve this problem thanks

I don't think this question has anything to do with JavaMail.
You would call that class from a JSP the same way you would call any
class from a JSP. And since you're using a static method, you don't
even have to worry about getting an instance of the class. Just think
of it like a "function".
There are examples of using JavaMail from a JSP application in the
JavaMail download bundle, although they're much more sophisticated
than this.
If you're having trouble with basic JSP programming, and the Java EE Tutorial
isn't helping, try the servlet and JSP support forum.

Similar Messages

  • BASIC Questions about JavaMail

    Hi Everyone
    I have some very basic questions about java mail.
    I have a weblogic web server. I think it's version 5 or something like that.
    when a user clicks a form on my application sends some information to my database (via my jsp/java program) , I need to send email to a person?
    Does anyone know how to do that ?
    Could someone please describe the process
    Stephen

    I would recommend that you first read the JavaMail design specifications http://java.sun.com/products/javamail/JavaMail-1.2.pdf
    Then, download JavaMail. It comes with a reference implementation of the API and also very good samples.
    Those samples should get you started very quickly on how to send email from Java program.

  • I'm new here, I need lotsa help and I found no toturial about JavaMail

    Hi there, people!
    I'm starting to use JavaMail just now and I don't know ANYTHING about it.
    For start, I need a program that looks inside a database and if a order was flagged as DONE I need it to send a mail to the client telling him it. All the logic part to do it is ok, but I still need to send the client (or clients) the mail. How do I do it? Do I really need JavaMail API? What SMTP server shoud I use (Yahoo?)??
    The thing is: I haven't found a TUTORIAL about it. If any of you can't answer the questions I just put in here, maybe you could tell me one place I can find a tutorial about it.
    Thanks in advance!

    And as to what SMTP server you should use: You should use one you are authorized to use. That will generally exclude public servers like Yahoo and Hotmail. If you are doing this for a company then that company would usually have its own SMTP server, which is the one you should use. If you are doing it for personal use then perhaps your ISP (Internet Service Provider, the people you pay to connect you to the Internet) allows you to use theirs. Ask them.
    PC²

  • No idea about javamail

    i found a code using google to send a mail
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SmtpGmail {
       public static void main(String[] args) {
         SmtpSsl smtp = null;
         // gmail username - CHANGE THIS
         String username = "[email protected]";
         // gmail password - CHANGE THIS
         String password = "password";
         // address to send mail to - CHANGE THIS
         String to = "[email protected]";
         try {     
           // create a new SmtpSsl instance connecting securely via port 465 using implicit SSL
           smtp = new SmtpSsl("smtp.gmail.com",465);
           // establish secure connection
           smtp.connect();
           // login using gmail account details
           smtp.login(username,password);
           // create new email message
           EmailMessage message = new EmailMessage();
           message.setTo(to);
           message.setFrom(username);
           message.setSubject("Sending email via Gmail SMTP");
           message.setBody("This is the body of the message");
           // send message
           smtp.send(message);
           // disconnect     
           smtp.disconnect();     
         } catch(Exception e) {
           // capture any exception and print to console
           e.printStackTrace();
    SmtpGmail.java:9: cannot find symbol
    symbol  : class SmtpSsl
    location: class SmtpGmail
         SmtpSsl smtp = null;
         ^
    SmtpGmail.java:21: cannot find symbol
    symbol  : class SmtpSsl
    location: class SmtpGmail
           smtp = new SmtpSsl("smtp.gmail.com",465);
                      ^
    SmtpGmail.java:30: cannot find symbol
    symbol  : class EmailMessage
    location: class SmtpGmail
           EmailMessage message = new EmailMessage();
           ^
    SmtpGmail.java:30: cannot find symbol
    symbol  : class EmailMessage
    location: class SmtpGmail
           EmailMessage message = new EmailMessage();
                                      ^
    4 errorsthis error is shown....is it because i couldnt add properly in environment variable??
    my classpath of user variable looks like this
    .;C:\javamail\javamail\mail.jar;C:\javamail\jaf\activation.jar;C:\javamail\javamail\lib\dsn.jar;C:\javamail\javamail\lib\imap.jar;C:\javamail\javamail\lib\mailapi.jar;
    C:\javamail\javamail\lib\pop3.jar;C:\javamail\javamail\lib\smtp.jar

    I don't know what API you're using but it's not JavaMail.
    The JavaMail FAQ will show you how to connect to Gmail, and will point you
    to the source code of example programs you can use.

  • Please help me to use javamail to send mail in servlet program

    hi
    i want to send simple mail from user [email protected] to user [email protected] using servlet program
    i can't compile the javamail demo program servlet "JavaMailServlet.java".
    i have this exception
    Note: SendMailServlet.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    i don't no how to do
    please help me if you have code
    thank's

    Given that you're having problems with your [url http://forum.java.sun.com/thread.jsp?forum=43&thread=536278&tstart=0&trange=30]demo mail code as well as your demo servlet code, perhaps you would be better served by learning about JavaMail, servlets, and perhaps Java in general (for example - the meaning of deprecated). Then you may be able to build your own servlet for handling mail or at least will be able to revise the demo code found elsewhere.
    Of course, if the purpose is really not to learn how to use Java, JavaMail, servlets, etc. but to simply create something that works then you could always hire someone to write the program for you.
    This is not intended to be rude or anything - just an observation and some food for thought.
    ∞ brewman ∞

  • How to use JavaMail to receive incomming email?

    Hello,
    I am a year 3 student and doing a final year project about web hosting.
    I want to know how to use JavaMail to receive and treat the incomming email. It means that the incoming email how to process and store the "message" in the recipient "folder" in the "store" class.
    If you have any optinions or examples or suggestion, please contact me.
    Thank you for your attention....

    First, it would be better to post questions about JavaMail in the JavaMail forum and not in the JSP forum.
    Second, the JavaMail download comes with a set of examples, including some that cover exactly what you ask.

  • How to send attachment(file) in javamail via JSP ?

    Dear Friends,
    Please guide me for :
    (1) my e-mail client is using JSP. So, hoW to send file-attachments via jsp ?
    Please specify example for attaching file(s) to a message object in JSP ( and only in JSP ).
    I have used HTML <input type="file" .... > control , but don't know how to bring that file to the jsp file and then attach it to the message object.
    Thank u.

    I wouldn't recommend using JSP to do that. I would use a servlet instead. Then you are just writing Java code, and to answer your two questions you need to learn about JavaMail (1) and get some already-written classes to do file uploads such as this one: http://www.servlets.com/cos/index.html (2).

  • I need javamail help

    hi guys, i need help in creating a auto mail system... i need to create a registration page then after the client submits, he should recieve a mail from the site... but our professor didn't teach us about javamail... im in big trouble cause next week is our project presentation already... can anyone give me some tutorials and codes? please please please please... and what is mime ? Please help me...

    Google keywords: "javamail tutorial".

  • JavaMail third party frameworks.

    Hi,
    Please, could you provide me information about JavaMail based third-party frameworks,
    which support any storage for e-mails and sending replication for didn't sent e-mails?
    Thanks in Advance.
    Iaroslav.

    You can create a RSL from a Library project you can read more here:
    http://livedocs.adobe.com/flex/3/html/help.html?content=rsl_02.html#220675

  • Mini JavaMail Questions

    Hi!
    I've been studying about JavaMail, I just have some questions regarding on sending emails using it. I'm just wondering if it can be traced by our administrator? I mean If I'm sending emails from my pc using it will it be a load to the network?
    Thank you so much Sir/Mam.
    Ryan
    p.s.
    Hi Monica & Ronillo!

    Hi!
    Thank you so much for the reply Sir, I don't know the idea for the "spamming". The administrators here in this client are so strict. It's not part of my job to study java, it's just that only here in the office that I could try this JavaMail because I dont have an internet at home. I'm just thinking that if the administrator sees that I'm sending emails using java they might block it. I'm also searching for any technology of setting up a mail server on a standalone pc at home that have no internet connection. Is it possible? And also would JavaMail still run? Thank you so much again Sir. I always think, It's just that sometimes my questions sounds stupid to other people.
    Ryan

  • Javamail books

    hi im planning to develop a college project on javamail.
    could sum1 plz help me by telling me where to start and what good books are available on it along with other things.
    looking frwrd for ur cooperation.
    sahil jethi

    Start on the main JavaMail web page - http://java.sun.com/products/javamail
    There are a few books that talk about JavaMail, but you should find everything you
    need under the Reference and Community links on the left side of that page.

  • How to send mail to the yahoo address?...

    I try to send the mail to the external address: [email protected]
    but the application is error:
    nested exception is:
         javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
         javax.mail.SendFailedException: 553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)
    Please help!
    Is there any resources about send mail by smtp about JavaMail?
    Thanks a lot!

    take a look at
    http://www.palomine.net/qmail/relaying.html
    http://www.palomine.net/qmail/selectiverelay.html

  • Please help me: what is the wrong in my code?

    Hi all ,
    I wrote a script in unix to send a mail, i am executing the script using java code, when i test the script separately in unix it is working properly , when i am executing it in java it is not working properly it is not showing any errors.
    UNIX script: Send_mail.ksh
    #!/bin/ksh
    . ./set_mail_details.ksh
    echo 'In script'
    subject=$1
    echo '\nsubject'
    echo $1
    echo "$subject" | sed 's/~/ /g' | read sub
    body_of_email=$2
    echo '\nBody'
    echo $2
    echo '\nMail List'
    to_list=$3
    echo $3
    echo "$body_of_email" | sed 's/~/ /g' | read body
    (echo "$body";echo '\n';cat U.CUE_CPM )| mailx -s "$sub" -r [email protected] "$to_list"
    if [ $? -eq 0 ]
    then
      echo "Mail is Sent"
    else
      echo "Mail is not sent(In script)"
    fijava code: sendMail.java
    import java.lang.*;
    import java.util.*;
    import java.io.*;
    public class sendMail
      public static void main(String argv[])
          /* This function will send a mail.*/
              String mailIds = "[email protected],[email protected]";
              try{
                   String subject="Test mail";
                       String body = "This is to test the code";
                       String exec_command = "send_mail.ksh "+subject+" "+body+" "+mailIds;
                       Process p = Runtime.getRuntime().exec(exec_command);
                            int exitVal=p.waitFor();
                            if (exitVal == 0)
                                    System.out.println("Mail Is Sent Successfully");
                            else
                                    System.out.println("Mail Is Not Sent ");
                     catch(Exception e)
                        System.out.println("Mail Delivary Failure due to following reasons.");
                            System.out.println("error in email:"+e.getMessage());
                            System.out.println("Cause:"+e.getCause());
                            System.out.println("to string:"+e.toString());
    }when i execute the sendMail i am getting the output as
    $ java sendMail
    Mail Is Sent Successfully
    but i didn't receive any mail.can any one please help in resolving my prob :((

    When using Runtime.exec(String) method, the parameter is split by whitespaces. The first token being the program to run, and each other being considerred as an argument to this program.
    In your test, the body contains whitespaces. Therefore, "This" is considered as one argument, and "is" as another one (mail list in this case...), etc.
    You should consider using the Runtime.exec(String[]) method instead, whith which you have control on the parameters (the first element of the array being the command and every subsequent element being an argument.)String[] exec_command = {"send_mail.ksh", subject, body, mailIds};
    Process p = Runtime.getRuntime().exec(exec_command);http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html
    Tim - What about JavaMail ?

  • How to include JAR file in NetBean library?

    i have downloaded JavaMail jar file and now i want to include this file into NetBean library. pls help me out.

    You can add the jar file to Netbeans as an external library by choosing 'Tools' on the menu bar and then selecting 'Library Manager'. In there you can give it a name and the path to the jar file. Once it is setup, if you go to your project properties, and click the 'Libraries' option on the left you will be able to add it. Select 'Add Library' and choose the one that you just created, it will now be part of your project.
    Alternatively, if you don't want to set it up as a library in Netbaeans, go straight to the project properties, select 'Libraries' and then select the 'Add Jar/Folder' option, now you can navigate to your jar file and add it to your project.
    For other info about JavaMail: http://java.sun.com/products/javamail/FAQ.html#install

  • Read In Email, parsing Attachments and converting them to PDF

    Dear Forum,
    When an email arrives, I want to check wether there are attachments present in this email. When there are .GIF, .PNG or .TIFF files attached, I want to convert them to a PDF.
    Does anybody knows how to do one of these steps in Java?
    1) parsing attachments out of email
    2)converting them to PDF
    Thank you,
    Stefan Tysbaert

    In your JavaMail download there is a directory containing examples of JavaMail code. One of those examples covers your first question.
    And the second question ("How do I convert a GIF file to PDF?") isn't a question about JavaMail.

Maybe you are looking for

  • Where do I find the download-link for "Adobe Design Std 5.5"?

    Hi. I wanna download the Adobe Design Std 5.5 on my new computer. I already deactivited it on my old computer. But now I'm desperatly searching a download-link to get the Adobe Design for my new computer. thanks for helping!!

  • Receive email and app alerts -- but no new updates

     I'm using the MyFico 3B monitoring, and several times, I have received an email and/or app notification of a new alert.. However, when I view my alerts on either the app or the myfico website, there are no new alerts.  Example:6/29/2015 5:39 PMDear

  • Removing servlet name from path

              Hi,           I have an appliaction that is launched like this : http://host:port/application/servlet           And I'd like to make it work so that I only have to write the host, port and application,           not the servlet. So does any

  • Can't get Adobe Photoshop (edit: Elements 12) to connect to internet

    I downloaded Adobe Photoshop on my computer and it was working great.  My computer crashed and now it won't connect to the internet.  Help

  • Re-activation blah blah blah

    i just bought a new computer today and when i reloaded the software a message came up saying i need to de-activate the other computer or in 30 days i will lose my software or some crap like that how on earth can i de-activate my old computer when it