sending a message using javamail
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jas_singh
Posted On:   Saturday, March 24, 2007 05:45 PM

Hi, i need to send a message using javamail to a yahoo account and came across your code. However when i try to implement this i come across errors such as Exception in thread "main" javax.mail.AuthenticationFailedException at javax.mail.Service.connect(Service.java:306) at javax.mail.Service.connect(Service.java:156) at javax.mail.Service.connect(Service.java:105) at javax.mail.Transport.send0(Transport.java:168) at javax.mail.Transport.send(Transport.java:98) at MailExample.main(MailExample.java:41) import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import javax.mail.Transport; public class   More>>

Hi,
i need to send a message using javamail to a yahoo account and came across your code. However when i try to implement this i come across errors such as
Exception in thread "main" javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at MailExample.main(MailExample.java:41)

			


import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.Transport;

public class MailExample {
public static void main (String args[]) throws Exception {
String smtpHost = "smtp.mail.yahoo.co.uk";
String popHost = "pop.mail.yahoo.co.uk";
String from = "from address";//args[0]; // with @yahoo.com
String to = "yahoo email address";//args[1];
String username = "username";//args[2];
String password = "password";//args[3];

// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", smtpHost);

props.put("mail.smtp.auth", "true");

// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);

// Pop Authenticate yourself
Store store = session.getStore("pop3");
store.connect(popHost, username, password);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to Yahoo's JavaMail");

// Send message
Transport.send(message);
}
}




what seems to be the problem? please help. Thanks in advance.
Regards,
Jas    <<Less

Re: sending a message using javamail

Posted By:   jas_singh  
Posted On:   Monday, March 26, 2007 08:13 AM

i dont think its got any thing to do with hard coding the username and password, because it checks the username and password and says its ok.

Re: sending a message using javamail

Posted By:   Anonymous  
Posted On:   Monday, March 26, 2007 02:30 AM

Hi Jas,

The User credentials that you have given might be wrong.in the above program you have given
String username = "username";//args[2];

String password = "password";//args[3];


your comments seems that you are tryig to get those username & passwords from the commandline.But you have hard coded the values there but not getting them from commandline.


Regards,
Krishna Rajendra A.
About | Sitemap | Contact