08 ส.ค.

สอนเขียน Web Application ด้วย grails on windows

  1. ให้ทำการ download jdk8 และ ทำการติดตั้ง
  2. ทำการ download grails spring ide ( http://download.springsource.com/release/STS/3.6.4.RELEASE/dist/e4.4/groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32.zip ) และทำการติดตั้ง
  3. ทำการ donwload grails binary https://grails.org/download.html เมื่อ download มาจะได้ .zip
27 ก.ค.

jsp sendemail by sendgrid

<%@page import=”javax.mail.PasswordAuthentication”%><%@page import=”javax.mail.PasswordAuthentication”%><%@page import=”javax.mail.Transport”%><%@page import=”javax.mail.internet.InternetAddress”%><%@page import=”javax.mail.Message”%><%@page import=”javax.mail.internet.MimeBodyPart”%><%@page import=”javax.mail.BodyPart”%><%@page import=”javax.mail.Multipart”%><%@page import=”javax.mail.internet.MimeMultipart”%><%@page import=”javax.mail.internet.MimeMessage”%><%@page import=”javax.mail.Session”%><%@page import=”javax.mail.Authenticator”%><%@page import=”java.util.Properties”%><%!private class SMTPAuthenticator extends javax.mail.Authenticator { String username; String password; public SMTPAuthenticator(String username,String password){ this.username=username; this.password=password; } public PasswordAuthentication getPasswordAuthentication() {   return new PasswordAuthentication(username, password); }}%>
<%String SMTP_HOST_NAME = “smtp.sendgrid.net”;String SMTP_PORT = “587”;String SMTP_AUTH_USER = “azure_87bf41746fc8425cd65a4813ac479079@azure.com”;String SMTP_AUTH_PWD = “#nJsxHC73XF1″;String from=”boonchai@roojai.com”;String to=”boonchai@roojai.com”;String subject=”test Mail”;String content=”Test SendMail”;

Properties properties = new Properties();properties.put(“mail.transport.protocol”, “smtp”);properties.put(“mail.smtp.host”, SMTP_HOST_NAME);properties.put(“mail.smtp.port”, SMTP_PORT);properties.put(“mail.smtp.auth”, “true”);properties.put(“mail.smtp.starttls.enable”,”true”);
Authenticator auth = new SMTPAuthenticator(SMTP_AUTH_USER,SMTP_AUTH_PWD);Session mailSession = Session.getDefaultInstance(properties,auth);

MimeMessage message = new MimeMessage(mailSession);
Multipart multipart = new MimeMultipart(“alternative”);BodyPart part1 = new MimeBodyPart();part1.setContent(content,”text/html; charset=UTF-8″);multipart.addBodyPart(part1);
message.setFrom(new InternetAddress(from));message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));message.setSubject(subject);message.setContent(multipart);
Transport transport = mailSession.getTransport();// Connect the transport object.transport.connect();// Send the message.transport.sendMessage(message, message.getAllRecipients());// Close the connection.transport.close();

%>