[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Mht mail with attachments

Posted on 2004-10-22
9
Medium Priority
?
1,117 Views
Last Modified: 2013-11-24
Hi,
Im working with JavaMail and I need to send MHT mails and MHT created in Word with attachments.
The point is to send HTML mails with attachments.

Any help?

Regards!
0
Comment
Question by:mjuri
[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
9 Comments
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12381834
I'm unfamiliar with the package you're using. But refer to the documentation with it. Details should be specified there.

HTH :)
[r.D]
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 272 total points
ID: 12381878
for emails to be sent make sure to send the content type to "text/html" a sample code will look like this:

  protected void sendMail( MailValueObject theMail  )
  {
    try
    {
        props.put(ENVIRONMENT_PROPERTIES_MAIL_SMTP_USER, user);
        props.put(ENVIRONMENT_PROPERTIES_MAIL_SMTP_HOST, host);
                
        mailSession = Session.getInstance(props, null);

        Message msg = new MimeMessage( mailSession );
        //msg.setContent
//        msg.setFrom();
        msg.setFrom( new InternetAddress( theMail.getFromAddress() ) );
        msg.setRecipients( Message.RecipientType.TO,
                            InternetAddress.parse(theMail.getToAddress() , false ) );
        if( theMail.getCcAddress() != null)
        {
          msg.setRecipients(Message.RecipientType.CC,
                            InternetAddress.parse(theMail.getCcAddress(), false));
        }
        if( theMail.getBccAddress() != null)
        {
          msg.setRecipients( Message.RecipientType.BCC,
                                  InternetAddress.parse(theMail.getBccAddress() , false ) );
        }
        msg.setSubject( theMail.getSubject() );


        msg.setContent( theMail.getBodyText(), "text/html");

        msg.setHeader("X-Mailer", mailer);
        msg.setSentDate( getCurrentTimeStamp() );

        Transport.send(msg);
      }
   }

where theMail is a normal been with the its member fields represents the single mail fields
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 264 total points
ID: 12382053
You just need to send the mht file as an attachment. Example here:

http://www.jguru.com/faq/view.jsp?EID=30251
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:mjuri
ID: 12382523
CEHJ,
In this case when the email is open, the email body to show is HTML or simple text?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 264 total points
ID: 12386096
here's an example of sending an image attachment with a html mail:

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class HtmlImageExample {
  public static void main (String args[]) throws Exception {
    String host = args[0];
    String from = args[1];
    String to = args[2];
    String file = args[3];

    // Get system properties
    Properties props = System.getProperties();

    // Setup mail server
    props.put("mail.smtp.host", host);

    // Get session
    Session session = Session.getDefaultInstance(props, null);

    // Create the message
    Message message = new MimeMessage(session);

    // Fill its headers
    message.setSubject("Embedded Image");
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

    // Create your new message part
    BodyPart messageBodyPart = new MimeBodyPart();

    // Set the HTML content, be sure it references the attachment
    String htmlText = "<H1>Hello</H1>" +
      "<img src=\"cid:memememe\">";

    // Set the content of the body part
    messageBodyPart.setContent(htmlText, "text/html");

    // Create a related multi-part to combine the parts
    MimeMultipart multipart = new MimeMultipart("related");

    // Add body part to multipart
    multipart.addBodyPart(messageBodyPart);

    // Create part for the image
    messageBodyPart = new MimeBodyPart();

    // Fetch the image and associate to part
    DataSource fds = new FileDataSource(file);
    messageBodyPart.setDataHandler(new DataHandler(fds));

    // Add a header to connect to the HTML
    messageBodyPart.setHeader("Content-ID","memememe");

    // Add part to multi-part
    multipart.addBodyPart(messageBodyPart);

    // Associate multi-part with message
    message.setContent(multipart);

    // Send message
    Transport.send(message);
  }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12386115
>>
CEHJ,
In this case when the email is open, the email body to show is HTML or simple text?
>>

You can choose whatever you want. What you can't do is to have the whole mht file automatically integrated *as* the body of the mail. You'd have to unpack it to do that
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

656 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