-1

If it possible to send emails with Gmail without the need to provide username and password from an interface, I want to make a class or a method and inside this calss or method put the password and username and then send the email, I read this question but they sais that you ned to provide the username and password using a interface, I want to create and automatic process that send automatic emails.

this is the question I read

Send email using java

Community
  • 1
  • 1
Bill_Data23
  • 659
  • 2
  • 14
  • 30
  • [Sending email with Gmail account tutorial](https://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/) – xenteros Sep 27 '16 at 12:36
  • You mean with hard-coded credentials? You can probably just run the OAuth2 once and save that credential to use, though I don't know if it times out, or you could configure the gmail account to still work with username and password. – Rup Sep 27 '16 at 12:37
  • @xenteros I don't think that adds anything to the question he already links? Or address the 'interface' part of his question? – Rup Sep 27 '16 at 12:38
  • yes with hard coded crdentials, if I do this implementation the one that is in the question I posted, the answer provide by Cheok Yan Cheng , Do i need to provide username and password everytime that I need to send a email?? – Bill_Data23 Sep 27 '16 at 12:40

1 Answers1

0

You could hard code the credentials, but someone could read these credentials if you share the source or executable form - this is at your risk. Every time you would like to send an email you need to provide the credentials, as it is in the answer from which you would like to get the code, the method takes credentials as parameters every time you send an email, but since the credentials will be hard coded, you don't need to enter them in GUI - it will be automatic.

Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
  • But if it is bad practice how automatic emails are being sent? I don't think that everytime that an automatic mail is being sent someone needs to provide their password and username, I'm creating a web app for a company the app it's not going to get out of the company, but what would be a more secure way to implement this? without having the password and username in the code – Bill_Data23 Sep 27 '16 at 13:44
  • The credentials are stored somwhere - for instance in the DB - user enters them once, so these credentials are stored somwhere outside the code. – Krzysztof Cichocki Sep 27 '16 at 13:47