我对这种电子邮件方法有疑问:
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();
}
}
问题是我的客户正在使用登录名是“ superinfo ”的邮件,而真正的邮件是“info@domain.com”。
当系统使用此邮件发送消息时,我得到:
com.sun.mail.smtp.SMTPSenderFailedException: 553 5.3.0 <superinfo@domain.com>...没有这样的用户