-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendMail.java
More file actions
49 lines (39 loc) · 2.35 KB
/
SendMail.java
File metadata and controls
49 lines (39 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
/** Construtor parametrizado da classe SendMail.
* @param ficha FichaCliente correspondente à ficha do cliente que perdeu a password.
*/
public SendMail(FichaCliente ficha) {
final String user = "costumeranafreitas@gmail.com";
final String password = "poo20172018";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(ficha.getEmail()));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(ficha.getEmail()));
message.setSubject("Recuperação de password da Aplicação POO-project 2017-2018");
message.setContent("Caro " +ficha.getNome()+ ",<html><br/>Muito obrigado por usar os Serviços POO-20172018 da universidade Minho. <br/> Recebemos um pedido de recuperação de dados da conta associada ao NIF: </html>" +ficha.getnif()+"<html> no nosso sistema.<br/> Estes são os seus dados </html>"+ficha.getNome()+":<html><br/><br/>Nome: </html>"+ficha.getNome()+ "<html><br/>NIF: </html>"+ficha.getnif()+"<html><br/>Morada: </html>"+ficha.getMorada()+"<html><br/>Email: </html>"+ficha.getEmail()+"<br/>Password: "+ ficha.getPassword() +"<br/><br/>Espero que tenha recebido os dados que desejava.<br/> Se alguma duvida persistir não hesite em contactar o nosso suporte em <a href=https://www.uminho.pt/PT>https://www.uminho.pt/PT</a><br/>Atenciosamente<br/>Ana Freitas <br/>UMinho!<br/><br/><img src='http://join.di.uminho.pt/images/org/ee-um.png' alt='https://www.uminho.pt/PT' style='width:400px;height:200px;'></html>", "text/html; charset=utf-8");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}