I have implemented a routine where when a user submits a form an email is sent to the administrator. For this I have used Java Mail API. And I setup a dummy account on Microsoft Outlook for sending out the emails. In the code I have hard-coded the password. I am concerned this will be a security issue when I host the webpage.
Here is my code.
I have written a private function:
private void getSession(){
this.session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication
getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "xxxxx_password_xxx");
}
});
}
In my public execute()
method I call the getSession()
method and generate the message.
public String execute() throws Exception {
getSession();
Message message = new MimeMessage(this.session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Form submit notification");
//...
}
Is it secure to hard code the password in the session method when I host the web page?
And if not, then some pointers to implement the alternatives.
Thanks!