Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Mht mail with attachments

Posted on 2004-10-22
9
Medium Priority
?
1,148 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
6 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
Industry Leaders: 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!

 

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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

577 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