@Grab(group="javax.mail", module="mail", version="latest.integration") import java.security.* import java.util.* import javax.mail.* import javax.mail.internet.* smtpHost = "smtp.gmail.com" smtpPort = "465" Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()) Properties props = new Properties() props.put("mail.smtp.host", smtpHost) props.put("mail.smtp.port", smtpPort) props.put("mail.smtp.auth", "true") props.put("mail.smtp.socketFactory.port", smtpPort); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory") props.put("mail.smtp.socketFactory.fallback", "false") Session session = Session.getDefaultInstance(props, [ getPasswordAuthentication: { return new PasswordAuthentication("youraccount@gmail.com", 'yourpassword') } ] as Authenticator ) Message msg = new MimeMessage(session) msg.setFrom(new InternetAddress( "youraccount@gmail.com","youraccount@gmail.com","iso-2022-jp")) msg.setRecipients(Message.RecipientType.TO, "recipient_address@gmail.com") msg.setSubject("Disk Free Space","iso-2022-jp") content = "path : free / total size \n" File.listRoots().each{ content += it.getAbsolutePath() + " : " + String.format("%8.2f", it.getFreeSpace()/1024/1024/1024) + "(G) / " + String.format("%8.2f", it.getTotalSpace()/1024/1024/1024) + "(G)\n" } msg.setText(content, "iso-2022-jp") Transport.send(msg)
動作環境
Groovy 1.8.0, JDK6 Update22
0 件のコメント:
コメントを投稿