Hi all,
I wanted to send a javaMail,i am geting the following error,
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at mailsample.sendEmail(mailsample.java:114)
at mailsample.main(mailsample.java:24)
My standard alone
java code asd follows:
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class mailsample {
public static void main(
String[] args) {
mailsample demo = new mailsample();
demo.sendEmail();
}
public void sendEmail() {
String from = "
sireesha@gmail.com";
String to = "
sireesha.m@gmail.com";
String subject = "Important Message";
String bodyText = "This is a important message with attachment";
String filename = "c:\\message.txt";
Properties properties = new Properties();
properties.put("mail.smtp.host", "localhost");
properties.put("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(properties, null);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setSentDate(new Date());
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);
// Set the email attachment file
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource(filename) {
@Override
public String getContentType() {
return "application/octet-stream"; }
}; attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
found some information like
i can disable McAfee Enterprise
Go to Viras scan console >> Access Protection >> Port Blocking tabe >> Rule >> check out check box for port 25 can solve this issue.
but i don't have this software,i have symantic end point protection software,there i don't have option like Viras scan console >> Access Protection
I am using virtual mechine, in Firewall.cpl in advance tab i tried by ticking the checkbox like INTERNET MAIL Server(SMTP) ,
still i am getting this error.
Please give me the solution.
Thanks in advance.
Sireesha