1. You'll need to format your message using HTML in order to include any
sort of styling and images in a message. This probably isn't a good idea
since not all people have HTML aware mail clients. If you do do this, you'll
have to use message.setContent( htmlString, "text/html" ) instead of the
setText method which sets the content type to "text/plain".
2. Just include "\r\n" in your string wherever you want a carriage
return/line feed pair.
3 and 4. The string can be as complex as it needs to be. It doesn't have to
be a single line of text the way in which we normally think of strings. Your
users can enter their own HTML tags into a textarea on a form, for example,
although the practicality of that escapes me. Plain text should be enough
for most purposes.
Hope this helps,
Jason Diamond.
-----Original Message-----
From: Ajay Jain [mailto:ajay@c...]
Sent: Thursday, September 07, 2000 5:47 AM
To: Java Server
Subject: Jav Mail : Body
Hi,
I am stuck with a problem on java mail. The Java mail is working fine ,
but I want to set the body of mail in HTML format.
1. How do I send the images in body of mail.
2. How do I enter the Carriage Control, Line feed characters.
3. Basically I have to format the body of mails.
4. Right now I am able to send only the strings.
I you can please put your comments in and tell me where to ammend the
code.
I am using following code...
import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.servlet.*;
import javax.activation.*;
import javax.servlet.http.*;
import javax.mail.internet.*;
import java.lang.*;
import java.net.*;
public class MailSend extends HttpServlet{
protected void doGet(HttpServletRequest request,
HttpServletResponse response)throws IOException
{
String fromg="manuj@h...";
String tog="ajay@c...,manuj_syal@h...";
String subg="java SendMail ser example";
String messageg="body to be entered here.";
try{
MailSending(fromg,tog,subg,messageg);
}catch(UnknownHostException ue){System.out.println(ue);}
catch(MessagingException me){System.out.println(me);}
}
public void MailSending(String from1,String to1,String subject1,String
message1) throws MessagingException, IOException{
String to=to1;
String from=from1;
String sub=subject1;
String msg=message1;
String smtpHost="192.168.0.151";
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.setText(msg);
Transport transport=session.getTransport("smtp");
transport.connect(smtpHost,"","");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}
Thanks And Regards,
Ajay
---
Do you know what you want from this list? How would you provide programmers
with the solutions they need? If you have the answers, and are willing to
work in Birmingham (UK), then you could be a List Manager. Please send CVs
and a covering letter to listsupport@p... for further information.
$subst('Email.Unsub')