Revision 92
web-presentation/trunk/eneraptor-web-presentation/grails-app/services/com/eneraptor/presentation/ContactMailService.groovy | ||
---|---|---|
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 |
} |
web-presentation/trunk/eneraptor-web-presentation/grails-app/controllers/com/eneraptor/presentation/MailController.groovy | ||
---|---|---|
1 |
package com.eneraptor.presentation |
|
2 |
|
|
3 |
class MailController { |
|
4 |
|
|
5 |
def contactMailService |
|
6 |
|
|
7 |
def send = { |
|
8 |
|
|
9 |
contactMailService.sendContactMail(params.from,params.content) |
|
10 |
|
|
11 |
render(text:"<xml>OK</xml>",contentType:"text/xml",encoding:"UTF-8") |
|
12 |
|
|
13 |
} |
|
14 |
|
|
15 |
} |
web-presentation/trunk/eneraptor-web-presentation/test/unit/com/eneraptor/presentation/ContactMailServiceTests.groovy | ||
---|---|---|
1 |
package com.eneraptor.presentation |
|
2 |
|
|
3 |
import grails.test.* |
|
4 |
|
|
5 |
class ContactMailServiceTests extends GrailsUnitTestCase { |
|
6 |
protected void setUp() { |
|
7 |
super.setUp() |
|
8 |
} |
|
9 |
|
|
10 |
protected void tearDown() { |
|
11 |
super.tearDown() |
|
12 |
} |
|
13 |
|
|
14 |
void testSomething() { |
|
15 |
|
|
16 |
} |
|
17 |
} |
web-presentation/trunk/eneraptor-web-presentation/test/unit/com/eneraptor/presentation/MailControllerTests.groovy | ||
---|---|---|
1 |
package com.eneraptor.presentation |
|
2 |
|
|
3 |
import grails.test.* |
|
4 |
|
|
5 |
class MailControllerTests extends ControllerUnitTestCase { |
|
6 |
protected void setUp() { |
|
7 |
super.setUp() |
|
8 |
} |
|
9 |
|
|
10 |
protected void tearDown() { |
|
11 |
super.tearDown() |
|
12 |
} |
|
13 |
|
|
14 |
void testSomething() { |
|
15 |
|
|
16 |
} |
|
17 |
} |
Also available in: Unified diff