Improve company productivity with a Business Account.Sign Up

x
?
Solved

Mht mail with attachments

Posted on 2004-10-22
9
Medium Priority
?
1,181 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

585 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