Results 1 to 2 of 2
  1. #1
    johniem is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default Javamail html mail sended as text

    I have this class:

    Java Code:
    public class MakeSend {
    	String userName;
    	String passWord;
    	Logger logger = Logger.getLogger(MakeSend.class);
    	public MakeSend(String userName,String passWord){
    		this.userName = userName;
    		this.passWord = passWord;
    	public String doSend(String smtp, StringBuffer msgBody, String toEmail, String subject, String mimetype){
    		Session mailSession;
    			Properties mailProps = new Properties();
    			mailProps.setProperty("mail.transport.protocol", "smtp");
    			mailProps.setProperty("", smtp);
    			mailProps.setProperty("mail.smtp.auth", "true");
    			Authenticator mailAuth = new SMTPAuthenticator();
    			mailSession = Session.getInstance(mailProps,mailAuth);
    			Transport transport = mailSession.getTransport();
    			MimeMessage msg = new MimeMessage(mailSession);
    			msg.setFrom(new InternetAddress(userName));
    			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
    			msg.setDataHandler(new DataHandler(
    					new javax.mail.util.ByteArrayDataSource(msgBody.toString(), mimetype)));
    			transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));
    		} catch (MessagingException mex) {			
    			logger.error("Email send failed, exception on: [" + toEmail + "] -" + mex);
    		        return "ERROR";
    		}catch (IOException ioex){
    			logger.error("Email send failed, exception on: [" + toEmail + "] -" + ioex);
    			return "ERROR";
    		finally	{
    			mailSession = null;
    		return "OK";
    	private class SMTPAuthenticator extends Authenticator {
    		public PasswordAuthentication getPasswordAuthentication(){
    			return new PasswordAuthentication(userName,passWord);
    This class is a part of a big project and i use it to send emails as html and plain text. The problem is that all emails is sended as text. If i pass the "text/html" mime type the mail is been sended as text too.
    I've create a main class in it , and use it seperately passing all the required parameters and it's working perfecty. But when i use it through the web application it's not.
    I'm really in a dead end here and I'm out of solutions, since i've tried to replace the javamail libraries with new ones, change the diretory of libraries and many other simple solutions that I can think of.
    Any advise will be really helpfull.

    Thanks in advance.

  2. #2
    akther is offline Member
    Join Date
    Aug 2010
    Rep Power

Similar Threads

  1. Replies: 2
    Last Post: 07-25-2009, 10:36 AM
  2. javamail exception: 557 mail head error
    By allanwakes in forum Java Servlet
    Replies: 2
    Last Post: 10-02-2008, 12:05 PM
  3. Replies: 0
    Last Post: 05-26-2008, 05:26 PM
  4. HTML mail body
    By Sudha in forum Java Servlet
    Replies: 0
    Last Post: 03-21-2008, 11:58 PM
  5. Sending mail Using JAVAMAIL
    By peiceonly in forum Advanced Java
    Replies: 3
    Last Post: 07-19-2007, 03:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts