Send email in Java via relay server -



Send email in Java via relay server -

i running java web application , attempting send email notifications it. when hosting application on 1 of our servers worked fine. pointed smtp.gmail.com on port 25 , messages able sent.

but hosting on 1 of our client's servers security purposes. happen block smtp domains , allow own (smtprelay.companyname.com). changed host in code, authentication failing.

is possible still authenticate gmail business relationship while using company's relay server send emails? best solution?

below relevant portion of code.

content = "message content"; list<string> recipients = list_of_recipient_email_addresses; properties props = new properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtprelay.companyname.com"); props.put("mail.smtp.port", "25"); props.put("mail.smtp.ssl.trust", "smtprelay.companyname.com"); props.put("mail.debug", "true"); session session = session.getinstance(props, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { //this email business relationship name , password set homecoming new passwordauthentication("supportemailaccount@gmail.com", "password"); } }); try{ mimemessage message = new mimemessage(session); message.setreplyto(new address[]{new internetaddress("no-reply@gmail.com")}); for(string recipient: recipients){ message.addrecipient(message.recipienttype.bcc,new internetaddress(recipient)); } message.setsubject(subject); message.setcontent(content,"text/html"); transport.send(message); homecoming true; }catch (messagingexception mex) { mex.printstacktrace(); homecoming false; }

here error maintain getting:

javax.mail.authenticationfailedexception: 535 5.7.3 authentication unsuccessful

it turns out company relay smtp server can used without authentication using spoofed email address has domain (e.g. anyusername@companyname.com). need authenticate against smtp.gmail.com rendered moot.

still curious if it's possible authenticate against blocked smtp while sending actual message through another. problem solved.

if curious how send email without authentication there many places how it, alter code in original question from:

props.put("mail.smtp.auth", "true"); . . . session session = session.getinstance(props, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { homecoming new passwordauthentication(email+"@"+domain, password); } });

change above portions following:

props.put("mail.smtp.auth", "false"); . . . session session = session.getinstance(props);

java email smtp

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -