• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JavaMail error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a mail server running on your machine ("localhost")?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.

Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
sireesha Makkapati
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,

i am not running the Mail Server locally,
Actually from the UAT Application,i am able to send the mails,but with the local configuration i am getting the following error,

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 265;
nested exception is:

I wanted to confirm is there any problem with SMTP port 25,i have written standard alone apllication,
I am very new to java mail,

with out running local mail server,can i solve my problem?
or
Could you please help me how to run local mail server ?

Thanks in advance..
Sireesha
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

with out running local mail server,can i solve my problem?


The line " properties.put("mail.smtp.host", "localhost") " tells JavaMail that you want to use a mail server on your local machine, so you need one.

Could you please help me how to run local mail server ?


One of the easiest ways might be to run Apache James, an open source mail server written in Java.
 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sireesha Makkapati wrote:with out running local mail server,can i solve my problem?



Just specify a working outgoing SMTP server. Its a lot easier then running your own. If you use thunderbird, eudora, outlook, etc. there is an account setup page. In it, you specify the incoming and outgoing hosts for mail.

Just put that instead of "localhost" in your properties.

Getting a mail server properly and securely setup is a non-trivial effort.
 
sireesha Makkapati
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using lotus notes,I don't know the SMTP Server name,
where can i find SMTP Server details?
 
Pat Farrell
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sireesha Makkapati wrote:I am using lotus notes


I haven't used Notes this century, but I remember it as being very different from the usual. There is usually a "Internet Mail to Notes gateway" for your Notes installation. I suggest you buy a beer or other drink for your local Lotus Notes admin.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic