Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Problem in sending mail - java program

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-01-2010
Member
 
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.
Reply With Quote
  #2  
Old 04-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,842
Re: Problem in sending mail - java program

Hello
Quote:
mbp1.setText
and
Quote:
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.
Reply With Quote
  #3  
Old 04-01-2010
Member
 
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
Quote:
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:
Quote:
------=_ 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
Reply With Quote
  #4  
Old 04-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,385
Re: Problem in sending mail - java program

Hello
You can try the following part of code, may be, this will help you.
Quote:
DataHandler data = new DataHandler(stringBuffer.function toString() {
[native code]
}(), "text / html; charset = UTF-8");
mbp1.setDataHandler(data);
Reply With Quote
  #5  
Old 04-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,842
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.
Quote:
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.
Reply With Quote
  #6  
Old 04-01-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem in sending mail - java program"
Thread Thread Starter Forum Replies Last Post
Error message 'There was a problem sending a command to the Program' in Internet Explorer 9 Ramanujan Networking & Security 5 02-12-2011 01:58 AM
Error message ‘There was a problem sending the command to the program’ while double clicking Excel 2010 file Wave Windows Software 5 14-05-2011 10:42 AM
Problem sending email windows mail vista VauGhna Windows Vista Mail 3 06-08-2010 08:40 AM
Problem in using regex in java program. Kasper Software Development 5 05-03-2010 04:39 PM
Problem launching .sh from java program Ash maker Software Development 5 16-01-2010 11:32 AM


All times are GMT +5.5. The time now is 08:14 PM.