Forums Register Login

JavaMail AuthenticationFailedException

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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);
}
}
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3816 times.
Similar Threads
Java Mail send message to Yahoo account
automatic mail from jsp page.
JavaMail
javamail jsp problem
java.mail without specifying SMTP server
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:12:07.