Results 1 to 6 of 6

Thread: Problem in sending mail - java program

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Problem in sending mail - java program

    Hello everyone,
    I have a concern for sending mail. The following code works perfectly in a test class or a hand. I use exactly the same code in my web application, I get much mail, but the content is HTML is misinterpreted. In short I am unable to send mail using this java program. I explored the trails related charset unsuccessfully
    Environment:
    java 1.5
    Tomcat 5.0
    Code:
    		try {
    			String = smtp_server PARAM_SMTP_SERVER;
    String sender_email = PARAM_SENDER_EMAIL;
    String mail_user = PARAM_EMAIL_USER;
    String mail_pwd = PARAM_EMAIL_PWD;
    Properties props = System.getProperties();
    props.setProperty("mail.trans.protocol", "smtp");
    props.setProperty("mail.host", Smtp_server);
    props.setProperty("mail.user", mail_user);
    props.setProperty("mail.password", Mail_pwd);
    			Session session = mailSession.getDefaultInstance(props, null);
    Transport trans = mailSession.getTransport("smtp");
    trans.connect(smtp_server, mail_user, mail_pwd);
    			InternetAddress sendineadd = new InternetAddress(sender_email);
    			MimeMessage message = new MimeMessage(mailSession);
    			message.setSubject("Mail Subject");
     
    			MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText(stringBuffer.function toString() {
        [native code]
    }());
    mbp1.setContent(stringBuffer.function toString() {
        [native code]
    }(),"text / html; charset = ISO-8859-1");
    			Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
     
    			message.setContent(mp);
    InternetAddress iad =new InternetAddress(myEmail);
    message.addRecipient(Message.RecipientType.TO, Iadress);
    message.setFrom(sendineadd);
    			trans.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
    trans.close();
     
    		}catch (Exception e)  {
    			e.printStackTrace();
    		}
    Please verify the following code.
    Last edited by ISAIAH; 04-01-2010 at 12:02 PM.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,856

    Re: Problem in sending mail - java program

    Hello
    mbp1.setText
    and
    mbp1.setContent
    encode both the text with the platform default encoding. The only way to have control over the encoding is to replace the call by
    Code:
    setDataHandler(MyDatasource)
    by providing a data source that you have implemented yourself.

  3. #3
    Join Date
    Dec 2009
    Posts
    202

    Re: Problem in sending mail - java program

    Hello
    Thank you for your response, tested your solution without success. I tested by changing the header, such
    mbp1.setText(stringBuffer.function toString() {
    [native code]
    }());
    mbp1.setHeader("Content-Type", "text / html; charset =\"iso-8859-1\"");
    mbp1.setHeader("Content-Transfer-Encoding", "8bit");
    Here are some of the email received:
    ------=_ Part_0_5763977.12
    Content-Type: text / html; charset ="utf-8"
    Content-Transfer-Encoding: quoted-printable
    <html> <body> <p> Dear, </ p> HELLO WORD </ p> Our Service

  4. #4
    Join Date
    Oct 2005
    Posts
    2,394

    Re: Problem in sending mail - java program

    Hello
    You can try the following part of code, may be, this will help you.
    DataHandler data = new DataHandler(stringBuffer.function toString() {
    [native code]
    }(), "text / html; charset = UTF-8");
    mbp1.setDataHandler(data);

  5. #5
    Join Date
    Feb 2008
    Posts
    1,856

    Re: Problem in sending mail - java program

    Hi
    Alternatively you can try this code, I have not tried it at my home still you can try and reply with your answer. You must also implement your own data source, she will give the content type, content, etc.
    mbp.setDataHandler(new DataHandler(mdatas));
    //...
    Public class mdatas implements DataSource{
    Public String getContentType(){.....}
    Public InputStream getInputStream() {......}
    Public String getName() {.....}
    Public OutputStream getOutputStream(){return null;}
    }
    Hope this will help you.

  6. #6
    Join Date
    Dec 2009
    Posts
    202

    Re: Problem in sending mail - java program

    Hello everyone,
    And well after a good time galley, I finally found it. there is a conflict between the jar "geronimo-javamail_1.4_spec-1.3.jar geronimo-andactivation_1.1_spec-1.0.2.jar. And those of "activation.jar"And"javamail.jar". Thank you to participants.

Similar Threads

  1. Replies: 5
    Last Post: 02-12-2011, 01:58 AM
  2. Replies: 5
    Last Post: 14-05-2011, 10:42 AM
  3. Problem sending email windows mail vista
    By VauGhna in forum Windows Vista Mail
    Replies: 3
    Last Post: 06-08-2010, 08:40 AM
  4. Problem in using regex in java program.
    By Kasper in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 04:39 PM
  5. Problem launching .sh from java program
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 11:32 AM

Posting Permissions

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