|
 |
pro_java_server thread: Java Mail
Message #1 by "Ajay" <ajay@c...> on Wed, 4 Oct 2000 19:50:35 -0700
|
|
Are you sure that's the correct code sample? It doesn't make any use of
addBodyPart.
addBodyPart actually wants an instance of BodyPart. One of MimeBodyPart's
constructors accepts an InputStream but you shouldn't need to use that.
Since BodyPart implements the Part interface which contains the
setContent( Object, String ) method that you used in your last code sample,
you can construct a new MimeBodyPart, call setContent on it with your HTML
string, and then addBodyPart it to your MimeMultipart. Finally, you can
setContent the multipart on your MimeMessage and send it.
The following sample is probably very similar to what you're trying to do:
Message message = new MimeMessage( session );
message.setFrom(
new InternetAddress( "jason@i..." ) );
message.setRecipient( Message.RecipientType.TO,
new InternetAddress( "ajay@c..." ) );
message.setSubject( "i dine on only the premium brands" );
// text part
BodyPart bodyPart1 = new MimeBodyPart();
bodyPart1.setText(
"but we're all on the market now\r\n" );
// html part
BodyPart bodyPart2 = new MimeBodyPart();
bodyPart2.setContent(
"<p>but we're all on the <b>market</b> now</p>", "text/html" );
Multipart multipart = new MimeMultipart( "alternative" );
multipart.addBodyPart( bodyPart1 );
multipart.addBodyPart( bodyPart2 );
message.setContent( multipart );
Transport.send( message );
I haven't tested (or even tried to compile) this but you should get the
idea.
Jason.
> -----Original Message-----
> From: Ajay [mailto:ajay@c...]
> Sent: Friday, October 06, 2000 5:32 PM
> To: Java Server
> Cc: Jason Diamond
> Subject: Re: Java Mail
>
>
> Hello Jason,
>
> I am facing problems with multipart.addBodyPart (txt);
>
> My messgage is in string format. anoe addBodyFormat expects
> inputStram. Can
> you please have a look at the code sample and suggest some
> suitable changes.
>
> public void SendMails (String smtpHost1,String from1,String to1,String
> subject1,String message1,
> String stdate1,String endate1,String sttime1,String name1,String
> entime1,String attendies1) throws MessagingException, IOException
> {
>
> String smtpHost=smtpHost1;
> String to=to1;
> String from=from1;
> String sub=subject1;
> StringBuffer msg=new StringBuffer("<html><body>");
> String stdate=stdate1;
> String endate="";
>
> String name=name1;
> String attendies=attendies1;
> // Message block
> msg.append("<table cellspacing='0' cellpadding='0'><tr><td
> bgcolor='#CCCCCC' ><b><font color='brown' face='Comic Sans MS,Arial'
> size='6'> EventCalendar.com</font></b><br>");
> msg.append("<font color='green' face='Comic Sans MS,Arial'
> size='5'><b>
> &nbs
> p; E mail Notification</b></font><br><br>");
> msg=msg.append("</table></body></html>");
>
> String msg1=msg.toString();
> Properties properties=System.getProperties();
> Session session=Session.getInstance(properties,null);
> MimeMessage message=new MimeMessage(session);
> message.setFrom(new InternetAddress(from)) ;
> InternetAddress[] tos = InternetAddress.parse((String)(to));
> message.setRecipients(Message.RecipientType.TO,tos);
> message.setSubject(sub);
>
> message.setContent(msg1,"text/html");
> Transport transport=session.getTransport("smtp");
>
> transport.connect(smtpHost,"","");
>
> transport.sendMessage(message, message.getAllRecipients());
>
> transport.close();
> }
>
>
>
>
>
> Ajay
> ----- Original Message -----
> From: Jason Diamond <jason@i...>
> To: Java Server <pro_java_server@p...>
> Sent: Thursday, October 05, 2000 7:50 AM
> Subject: RE: Java Mail
>
>
> > Create a MimeMultipart with an "alternative" subtype. Add a plain text
> > version of your message as the first body part and the HTML
> version as the
> > second.
> >
> > Multipart multipart = new MimeMultipart( "alternative" );
> > multipart.addBodyPart( textVersion );
> > multipart.addBodyPart( htmlVersion );
> > message.setContent( multipart );
> >
> > MIME-aware mail agents will display the appropriate version.
> MIME-unaware
> > mail agents will display both but since the plain text version appears
> > first, they should be able to read it.
> >
> > The multipart type and it's subtypes are explained rather thoroughly in
> RFC
> > 2046. Here's what it says about alternative:
> >
> > 5.1.4. Alternative Subtype
> >
> > The "multipart/alternative" type is syntactically identical to
> > "multipart/mixed", but the semantics are different. In particular,
> > each of the body parts is an "alternative" version of the same
> > information.
> >
> > ...
> >
> > In general, user agents that compose "multipart/alternative" entities
> > must place the body parts in increasing order of preference, that is,
> > with the preferred format last. For fancy text, the sending user
> > agent should put the plainest format first and the richest format
> > last. Receiving user agents should pick and display the last format
> > they are capable of displaying. In the case where one of the
> > alternatives is itself of type "multipart" and contains unrecognized
> > sub-parts, the user agent may choose either to show that alternative,
> > an earlier alternative, or both.
> >
> > Hope this helps,
> > Jason.
> >
> > -----Original Message-----
> > From: Ajay [mailto:ajay@c...]
> > Sent: Wednesday, October 04, 2000 7:51 PM
> > To: Java Server
> > Subject: Java Mail
> >
> >
> > Hello friends,
> >
> > I am in a working on Java mail through SMTP server. Java mail is working
> > fine. By problem is that I want to send mails in a formatted way..like
> with
> > colours and images..If I set the contenttype to HTML and send
> the mails in
> > form of HTML tags , some mail clients process these tags and
> show the mail
> > in proper way. But some mail clients show the tags itself. How do I get
> > around with this problem.
> > For the clients that does not process HTML tags, do I have to send the
> mail
> > as an attachment. I don't really know the solution to this.
> >
> > Any help is highly appreciated.
> >
> > Thanks & Regards,
> > Ajay
> > ---
> > To place your message here, or to sponsor this list, please e-mail
> > mailto:p2pinfo@w...?subject=MediaPack, remembering to
> provide contact
> > details for yourself. We will e-mail you a Media Pack within 24 hours.
> > $subst('Email.Unsub')
> >
> >
> > ---
> > To place your message here, or to sponsor this list, please e-mail
> mailto:p2pinfo@w...?subject=MediaPack, remembering to provide contact
> details for yourself. We will e-mail you a Media Pack within 24 hours.
> $subst('Email.Unsub')
> >
>
|
|
 |