zoukankan      html  css  js  c++  java
  • ubuntu下的代码格式化工具

    indent -kr -i4   SimpleMail.java 可以用,但是太简单

    astyle 这个工具不错

    http://astyle.sourceforge.net/

     

    astyle --style=java --style=allman   -f  SimpleMail.java

    发送邮件的java代码!!亲测可以用

    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    
    import java.util.Properties;
    
    public class SimpleMail
    {
    
        private static final String SMTP_HOST_NAME = "smtp.host.com";
        private static final String SMTP_AUTH_USER = "no-replay@xxxx.com";
        private static final String SMTP_AUTH_PWD = "password";
    
        public static void main(String[]args) throws Exception
        {   
            new SimpleMail().test();
        }   
        public void test() throws Exception
        {   
            Properties props = new Properties();
            props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtp.auth", "true");
    
            Authenticator auth = new SMTPAuthenticator();
            Session mailSession = Session.getDefaultInstance(props, auth);
    
            // uncomment for debugging infos to stdout
            // mailSession.setDebug(true);
            Transport transport = mailSession.getTransport();
    
            MimeMessage message = new MimeMessage(mailSession);
            message.setContent("This is a test", "text/plain");
            message.setFrom(new InternetAddress("xxx.com"));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress("12354656@qq.com"));
    
            transport.connect();
            transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
            transport.close();
        }   
        private class SMTPAuthenticator extends javax.mail.Authenticator
        {   
            public PasswordAuthentication getPasswordAuthentication()
            {
                String username = SMTP_AUTH_USER;
                String password = SMTP_AUTH_PWD;
                return new PasswordAuthentication(username, password);
            }
        }
    }
    

      

  • 相关阅读:
    灌溉 最小生成树
    queue的应用uva540
    大数相加
    对于jquery实现原理的浅谈
    div+CSS实现页面的布局要点记录
    spring注解注入的学习
    jsp内置对象学习记录
    web应用的乱码解决
    新发现:排序算法时间复杂度只有O(3n),命名为"wgw"排序法
    java编写的Http协议的多线程下载器
  • 原文地址:https://www.cnblogs.com/oxspirt/p/7452911.html
Copyright © 2011-2022 走看看