Javamail - sending mail with login different from email
Got a problem with my email method, code below:
public static void send( final String username, final String password,
String recipientEmail, String ccEmail, String title, String message,
String from, String host, String port )
throws AddressException, MessagingException
{
try
{
Session session;
Properties props = System.getProperties();
props.setProperty( "mail.smtps.host", host );
props.setProperty( "mail.smtp.port", port );
props.setProperty( "mail.mime.charset", "utf8" );
session = Session.getInstance( props, null );
// session.setDebug( true );
String uFrom = from;
// setting encoding properly
/*
* try { uFrom = new String( from.getBytes( "UTF-8" ),
"ISO-8859-1" ); } catch (
* UnsupportedEncodingException e ) { // logi ! }
*/
// -- Create a new message --
final MimeMessage msg = new MimeMessage( session );
// -- Set the FROM and TO fields --
msg.setFrom( new InternetAddress( username ) );
msg.setRecipients( Message.RecipientType.TO,
InternetAddress.parse( recipientEmail, false ) );
if ( ccEmail.length() > 0 )
{
msg.setRecipients( Message.RecipientType.CC,
InternetAddress.parse( ccEmail, false ) );
}
InternetAddress adress = new InternetAddress( username, uFrom );
adress.setAddress( username + "@naszedziecko.com.pl" );
adress.setPersonal( uFrom, "ISO-8859-2" );
msg.setSubject( title, "utf-8" );
msg.setFrom( adress );
msg.setText( message, "utf-8" );
msg.setSentDate( new Date() );
SMTPTransport t = (SMTPTransport) session.getTransport( "smtps" );
t.connect( host, username, password );
t.sendMessage( msg, msg.getAllRecipients() );
t.close();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
And the problem is that my client is using mail where login is eg.
'superinfo' and the real mail is 'info@domain.com'.
When system is using this mail to send a message i get:
com.sun.mail.smtp.SMTPSenderFailedException: 553 5.3.0 ... No such user
No comments:
Post a Comment