java - javax authenticator refer to same email address -
here code use create session send email:
props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.enablessl.enable","true"); logger.trace("1. emailfromaddress: " + emailfromaddress); session = session.getdefaultinstance(props,new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { logger.trace("2. emailfromaddress + " pass: " + password); return new passwordauthentication(emailfromaddress, password); } });
then try input emailfromaddress = "abc@yahoo.com" , password. can authenticate address , send email successfully, ,
1. emailfromaddress: abc@yahoo.com 2. emailfromaddress: abc@yahoo.com pass: *****
i try send different emailfromaddress = "xyz@gmail.com" --> time failed send , log printout as:
1. emailfromaddress: xyz@gmail.com --> correct 2. emailfromaddress: abc@yahoo.com pass: ***** --> still refer old account
is there cache of session authenticator?
there some kind of cache: you've created authenticator
once in example, , set on default session. since object lives forever (or @ least until jvm terminates) behave same way @ every invocation.
maybe use getdefaultusername()
authenticator
supply user name?
another option might re-configure new authenticator
every mail send. can supply correct username on every attempt.
Comments
Post a Comment