Hello everyone,
I am developping a servlet which sends a registration confirmation in html
format,with images, to a new user.
I have run the programming using two different email addresses:
I was able to get the expected output with the first email sent to my
company mail server .The second email sent to yahoo mail server doesn't show
images!
I wonder where is the mistake.
Please, I need your help.
Thanks in advance.
Bobo
-----
Here is the function I am using to send the email:
public void sendNotification(String msgsender,String msgreceiver,String
msgsubject,String msgbody){
String from = msgsender;
String to = msgreceiver;
String subject =msgsubject;
String contentbody = msgbody;
try {
//Create the JavaMail session
Properties props = System.getProperties();
// could use Session.getTransport() and Transport.connect()
// assume we're using SMTP
props.put("mail.smtp.host", smtpHost);
// Get a Session object
Session session = Session.getDefaultInstance(props, null);
// construct the message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
msg.setSubject(subject);
MimeMultipart mp = new MimeMultipart();
mp.setSubType("related");
MimeBodyPart mbpOne= new MimeBodyPart();
String html =
"<html><head><title></title></head><body>"+
"<table border=\"0\" width=\"20\" height=\"50\" cellspacing=\"0\"
cellpadding=\"0\"> "+
"<tr><td>"+
"<table border=\"0\" width=\"18\" bordercolor=\"#0000FF\"
cellspacing=\"0\" cellpadding=\"0\" height=\"20\"> "+
"<tr><td bgcolor=\"#0000FF\"><img border=\"0\" src=cid:21958@logo$
width=\"55\" height=\"48\"><img border=\"0\" src=cid:1991975@ewarna$
width=\"180\" height=\"27\"><img border=\"0\" src=cid:1947@ewarnacolorbar$
width=\"260\" height=\"10\"></td>"+
"</tr><tr> <td bordercolor=\"#0000FF\"> "+
contentbody+
"</td></tr></table></td></tr></table>"+
"<table border=\"1\" width=\"500\" bordercolor=\"#FFFFFF\"
cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#0000FF\"> "+
"<tr><td></td></tr></table></body></html>";
mbpOne.setContent(html,"text/html");
MimeBodyPart mbpTwo = new MimeBodyPart();
FileDataSource fdsTwo = new
FileDataSource("C:/Tomcat/webapps/ROOT/IMG/m_logo.gif");
mbpTwo.setFileName(fdsTwo.getName());
//mbpTwo.setText("eWarna.com logo");
mbpTwo.setDataHandler(new DataHandler(fdsTwo));
mbpTwo.setHeader("Content-ID","21958@logo$");
MimeBodyPart mbpThree = new MimeBodyPart();
FileDataSource fdsThree = new
FileDataSource("C:/Tomcat/webapps/ROOT/IMG/ewarna.gif");
mbpThree.setFileName(fdsThree.getName());
//mbpThree.setText("eWarna.com");
mbpThree.setDataHandler(new DataHandler(fdsThree));
mbpThree.setHeader("Content-ID","1991975@ewarna$");
MimeBodyPart mbpFour = new MimeBodyPart();
FileDataSource fdsFour = new
FileDataSource("C:/Tomcat/webapps/ROOT/IMG/colourbar.gif");
mbpFour.setFileName(fdsFour.getName());
//mbpFour.setText("Color bar");
mbpFour.setDataHandler(new DataHandler(fdsFour));
mbpFour.setHeader("Content-ID","1947@ewarnacolorbar$");
mp.addBodyPart(mbpOne);
mp.addBodyPart(mbpTwo);
mp.addBodyPart(mbpThree);
mp.addBodyPart(mbpFour);
msg.setContent(mp);
msg.setSentDate(new Date());
Transport.send(msg);
status="A Registration confirmation was sent to"+" "+userfname+"
"+userlname;
}
catch (AddressException e){
status = "There was an error parsing the addresses.";
}
catch (SendFailedException e) {
status = " There was an error sending the message to"+"
"+e.getValidUnsentAddresses()+" "+"="+" "+to;
status ="Message could not be sent to"+" "+e.getInvalidAddresses()+"
"+"="+to+" "+"account"+" "+". "+to+" "+"could be invalid!";
}
catch (MessagingException e) {
status= "There was an unexpected error.";
}
System.out.println(status);
}//end of sendNotification()
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html