root / web-presentation / trunk / eneraptor-web-presentation / grails-app / services / com / eneraptor / presentation / ContactMailService.groovy @ 92
History | View | Annotate | Download (1.33 KB)
1 |
package com.eneraptor.presentation
|
---|---|
2 |
|
3 |
import javax.mail.*; |
4 |
import javax.mail.internet.*; |
5 |
|
6 |
import java.util.Properties; |
7 |
|
8 |
class ContactMailService { |
9 |
|
10 |
private static final String SMTP_HOST_NAME = "smtp.gmail.com"; |
11 |
private static final int SMTP_HOST_PORT = 465; |
12 |
private static final String SMTP_AUTH_USER = "eneraptor@gmail.com"; |
13 |
private static final String SMTP_AUTH_PWD = "malotokavelikomuzike"; |
14 |
|
15 |
static transactional = true |
16 |
|
17 |
def sendContactMail(String fromVal, String textVal) { |
18 |
|
19 |
Properties props = new Properties(); |
20 |
|
21 |
props.put("mail.transport.protocol", "smtps"); |
22 |
props.put("mail.smtps.host", SMTP_HOST_NAME);
|
23 |
props.put("mail.smtps.auth", "true"); |
24 |
// props.put("mail.smtps.quitwait", "false");
|
25 |
|
26 |
Session mailSession = Session.getDefaultInstance(props); |
27 |
mailSession.setDebug(false);
|
28 |
Transport transport = mailSession.getTransport(); |
29 |
|
30 |
MimeMessage message = new MimeMessage(mailSession);
|
31 |
message.setSubject("Eneraptor - new message from " + fromVal);
|
32 |
message.setContent(textVal, "text/plain");
|
33 |
|
34 |
message.addRecipient(Message.RecipientType.TO, new InternetAddress("eneraptor@fri.uni-lj.si")); |
35 |
|
36 |
transport.connect (SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD); |
37 |
|
38 |
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); |
39 |
transport.close(); |
40 |
|
41 |
} |
42 |
} |