• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail error

 
sireesha Makkapati
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a mail server running on your machine ("localhost")?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42970
73
  • Mark post as helpful
  • send pies
  • 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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!