Пример #1
0
        static void Main()
        {
            try
            {
                String recipient = "*****@*****.**";
                String subject   = "Hello";
                String content   = "Hello JavApi user!";
                String from1     = "*****@*****.**";

                java.util.Properties props = new java.util.Properties();
                props.put("mail.smtp.host", "post.example.com");
                props.put("mail.smtp.port", "25");
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.user", "*****@*****.**");
                props.put("mail.smtp.password", "secret");
                javax.mail.Session session = javax.mail.Session.getDefaultInstance(props);
                javax.mail.Message msg     = new javax.mail.internet.MimeMessage(session);
                javax.mail.internet.InternetAddress addressFrom = new javax.mail.internet.InternetAddress(from1);
                msg.setFrom(addressFrom);
                javax.mail.internet.InternetAddress addressTo = new javax.mail.internet.InternetAddress(recipient);
                msg.setRecipient(javax.mail.Message.RecipientType.TO, addressTo);
                msg.setSubject(subject);
                msg.setContent(content, "text/plain");
                javax.mail.Transport.send(msg);
            }
            catch (javax.mail.SendFailedException)
            {
            }
            catch (javax.mail.MessagingException)
            {
            }
        }
Пример #2
0
        static void Main()
        {
            try
            {

                String recipient = "*****@*****.**";
                String subject = "Hello";
                String content = "Hello JavApi user!";
                String from1 = "*****@*****.**";

                java.util.Properties props = new java.util.Properties();
                props.put("mail.smtp.host", "post.example.com");
                props.put("mail.smtp.port", "25");
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.user", "*****@*****.**");
                props.put("mail.smtp.password", "secret");
                javax.mail.Session session = javax.mail.Session.getDefaultInstance(props);
                javax.mail.Message msg = new javax.mail.internet.MimeMessage(session);
                javax.mail.internet.InternetAddress addressFrom = new javax.mail.internet.InternetAddress(from1);
                msg.setFrom(addressFrom);
                javax.mail.internet.InternetAddress addressTo = new javax.mail.internet.InternetAddress(recipient);
                msg.setRecipient(javax.mail.Message.RecipientType.TO, addressTo);
                msg.setSubject(subject);
                msg.setContent(content, "text/plain");
                javax.mail.Transport.send(msg);
            }
            catch (javax.mail.SendFailedException/*sfe*/)
            {

            }
            catch (javax.mail.MessagingException/*me*/)
            {
            }
        }