• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java mail is being sent as an attachment using ant but as an inline when prog run from eclipse

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing a strange problem when I am running my java mail code from eclipse it is being sent as an inline message but when same java code is being executed from an ant script than it is being sent as an attachment I have shared the code for sending java mail below, Please help me with this.



package experimental_report;

import java.io.File;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;

import javax.mail.Message;


import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;








import com.gui_auto.utilities.CommonFunctions;

public class SendMail
{
public static void main(String[] args)
{
Properties mailProps=new Properties();
final String username="user";
final String password="password";
mailProps.put("mail.smtp.host", "smtp.gmail.com");
mailProps.put("mail.smtp.socketFactory.port", "465");
mailProps.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
mailProps.put("mail.smtp.auth", "true");
mailProps.put("mail.smtp.port", "465");
Session session=Session.getInstance(mailProps, new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
// TODO Auto-generated method stub
return new PasswordAuthentication(username,password);
}
});

try
{
Message message=new MimeMessage(session);

message.setFrom(new InternetAddress("xyz@gmail.com"));
message.setSubject("Fonts.com sanity automation report for Win7 Firefox 26");
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("abc@mailinator.com"));
DataSource source=new FileDataSource(new File("//pathOfFile/finalReport.html"));
message.setDataHandler(new DataHandler(source));
message.setFileName("finalReport.html");
message.setDisposition(Message.INLINE);
message.saveChanges();
Transport.send(message);

System.out.println("mail sent");

}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
session=null;
mailProps.clear();

}

}
}


ant script

<target name="email">
<java classpathref="WebAutomation.classpath" classname="experimental_report.SendMail">
</java>
</target>
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a start I would check the classpaths you are using in those two situations and find out whether you are using the same version of JavaMail in both.
 
Gupta Ishan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

I checked the version of java mail in both cases and they are same, Can there be any other thing which is causing this issue?

 
Gupta Ishan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone please help me with this?
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the headers of the two mail messages which are different. You should find evidence that they were sent by JavaMail and you might find more interesting evidence. At any rate it's probable that the difference is caused by some configuration difference between the two systems. For code it's easy to say "Post your code" but for configuration we can't say "Post your configuration" because that could be all sorts of things. You could also modify your code so that it inserts the JavaMail version number into the message.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic