Solved

Sending Attachments with emails

Posted on 2002-04-02
7
202 Views
Last Modified: 2013-11-24
Hi,
 I am trying to send an attachment with an email sent from a servlet. I can send normal emails fine (i.e. emails without attachments). However I'm not to sure how to do so with an attachment.
Here is my code for an email without an attachment. Could you let me know how to modify it to include the sending of an email..

My Code:

  public void emailAttachmentTestRequest(HttpServletRequest request,
                                HttpServletResponse response,
                                HttpSession httpSession) throws ServletException, IOException {

    System.err.println("--- emailing AttachmentTest");

    String from = null;
    String to = null;
    SmtpClient smtp = null;
    PrintStream msg = null;

    smtp = new SmtpClient("smtp.test.com");
    from = "test@test.com";
    to = "test@test.com";

    smtp.from(from);
    smtp.to(to);
    msg = smtp.startMessage();

    try {
      msg.println("From: " + from);
      msg.println("To: " + to);
      msg.println("Subject: Testing Email");
      msg.println("This is the Test text");
      smtp.closeServer();
    }
    catch (IOException e) {
      System.err.println("err sending email" + e.getMessage());
    }
  }

 


0
Comment
Question by:seoirse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Author Comment

by:seoirse
ID: 6913251
From reading an article. It loks to me that using SMTPClient it isnot possible to send attachments with this. If you know how to use the JavaMail class to do so then could you let me know also.
0
 
LVL 3

Accepted Solution

by:
msterjev earned 100 total points
ID: 6913488
Just download JavaMail API. Look at the MimeMultipart and BodyPart classes. There is tutorial in pdf format and full example code for sending mail atachments:

http://java.sun.com/products/javamail/index.html

Be cool and use this standard J2EE API unstead of na old one.
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6913521
If you can wait reading the the whole tutorial here is the whole example of using JavaMail and sending attachments:

http://softwaredev.earthweb.com/java/sdjjavase/article/0,,12395_618471,00.html

Enjoy.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:msterjev
ID: 6915165
The points, please!
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6915737
The points, please!
0
 

Author Comment

by:seoirse
ID: 6917540
Points are yours msterjev
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6917584
You welcome!
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question