dcsimg
Plain text and HTML in same mail
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shanchar_Mahmood
Posted On:   Sunday, June 2, 2002 09:40 PM

How can i send a mail which contains plain text and HTML both at the same time

Re: Plain text and HTML in same mail

Posted By:   Anonymous  
Posted On:   Wednesday, June 19, 2002 11:44 PM

EmailAddressesData tempRecip = null;

Properties props = new Properties();
props.put("mail.smtp.host", "firedrum.com");
Session session = Session.getDefaultInstance(props, null);
Message msg = null;

MimeMultipart content = null;

MimeBodyPart text = null ;
MimeBodyPart html = null;


try
{

InternetAddress address = new InternetAddress();
InternetAddress[] replytoaddressarray = {new InternetAddress()};
InternetAddress replytoaddress = new InternetAddress();

//Use our address for address that bounce
InternetAddress fromaddr = new InternetAddress("email@firedrum.com");
//Use our address for bounces



for (int i = 0; i < recipients.size(); i++)
{

try
{

msg = new MimeMessage(session);
content = new MimeMultipart("alternative");
text = new MimeBodyPart();
html = new MimeBodyPart();

tempRecip = (EmailAddressesData)recipients.elementAt(i);


try
{fromaddr.setPersonal(frompersonaltext);}
catch(Exception e)
{ SharedUtilities.logError(e);}


msg.setFrom(fromaddr);

address.setAddress(tempRecip.getEmail());
//Use client from address for reply to
replytoaddress.setAddress(from);
replytoaddressarray[0] = replytoaddress;

msg.setReplyTo(replytoaddressarray);

//Records date and increments send total
tempRecip.updateLastSent();


msg.setRecipient(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());

text.setText( "Your E-mail client can not read a html message.
Please click here to get your message
http://www.firedrum.com/"+clientid+"/newsletter.jsp?memberid="+tempRecip.getID()+"&clientid="+clientid+"
");
text.setHeader("MIME-Version" , "1.0" );
text.setHeader("Content-Type" , "text/plain; charset="iso-8859-1"" );
text.setHeader("Content-Transfer-Encoding","8bit");

//String temp = setPersonalization(tempRecip.getFName(),tempRecip.getID());

//out.println(temp.length());

html.setContent(setPersonalization(tempRecip.getFName(),tempRecip.getID()), "text/html");
html.setHeader("MIME-Version" , "1.0" );
html.setHeader("Content-Type" , "text/html; charset="iso-8859-1"" );
html.setHeader("Content-Transfer-Encoding","7bit");

content.addBodyPart(text);
content.addBodyPart(html);

//msg.setContent(setPersonalization(tempRecip.getFName(),tempRecip.getID()),"text/html");

msg.setContent( content );
msg.setHeader("MIME-Version" , "1.0" );
msg.setHeader("Content-Type" , content.getContentType() );
msg.setHeader("Content-Transfer-Encoding","7bit");


Transport.send(msg);
numSent++;

}
catch (Exception e)
{
SharedUtilities.logError(e);
}


}

}
catch (Exception e)
{
SharedUtilities.logError(e);
}

Re: Plain text and HTML in same mail

Posted By:   John_Zukowski  
Posted On:   Wednesday, June 5, 2002 12:01 AM

Read the FAQ and see.
About | Sitemap | Contact