• 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

JavaMail AuthenticationFailedException

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone,

I'm having trouble getting my JavaMail to work.

My code is



The error I get is

javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.AuthenticationFailedException


Both my username and password fields are correct.
What is wrong?
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bron Czimes:
hi everyone,

I'm having trouble getting my JavaMail to work.

My code is

The error I get is

javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.AuthenticationFailedException


Both my username and password fields are correct.
What is wrong?



Try this it works for me

import java.util.*;
import java.io.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;


public class MailClient
{
private static final String SMTP_MAIL="smtp";
private String smtpHost = "smtp.blabla.co.om",
user = "", //Proxy login & password... This can be empty ("") ;
password = "";


public MailClient( String smtpHost,String user, String password)
{
this.smtpHost = smtpHost;
this.user = user;
this.password = password;
}


private void sendMsg( String from, String subject, String message,String[] toAddress,String[] attachments ) throws Exception
{


Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(props, null);



Message newMessage = new MimeMessage(session);
newMessage.setFrom(new InternetAddress(from));
newMessage.setSubject(subject);


Object content = message;
String debugText = "Subject: " + subject;
log("Sending Text message (" + debugText + ")");
newMessage.setText((String)content);


// Send Message
try
{
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(smtpHost, user, password);
transport.sendMessage(newMessage, getInternetAddress(toAddress) );
}
catch (Exception e )
{
log(e.toString());
}
}

private InternetAddress[] getInternetAddress( String[] toAddresses ) throws Exception
{
InternetAddress[] inetAddr = null;
try
{
inetAddr = new InternetAddress[toAddresses.length + 1];
for ( int i=0;i< toAddresses.length;i++ )
{
inetAddr[i] = new InternetAddress(toAddresses[i]);
}
}
catch (Exception e )
{
log(e.toString());
}
return inetAddr;
}

private void log(String s)
{
System.out.println(new Date() + " " + s);
}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic