|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class sendMail { public static void main(String args[]) throws Exception { String host = "smtp.sina.com.cn"; String from = "javamail@sina.com"; String to = "javamail@china.com"; String username = "javamail"; String password = "password"; // Get system properties // Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中 Properties props = new Properties(); // Setup mail server props.put("mail.smtp.host", host); props.put("mail.smtp.auth", "true"); //这样才能通过验证 // Get session Session session = Session.getDefaultInstance(props); // watch the mail commands go by to the mail server session.setDebug(true); // Define message MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Hello JavaMail"); message.setText("Welcome to JavaMail"); // Send message message.saveChanges(); Transport transport = session.getTransport("smtp"); transport.connect(host, username, password); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } } 返回类别: 教程 上一教程: JAVA环境变量的设置与调试 下一教程: 应用JAVA技术实现数据库应用系统 您可以阅读与"发邮件时终于可以通过SINA的SMTP验证了(附代码)"相关的教程: · 发邮件时终于可以通过SINA的SMTP验证了 · 用JAVAMAIL发邮件(含附件) · JAVAMAIL发信的连接SMTP验证的问题 · 使用J2ME技术实现简朴的动画(附代码实现) · 一段带SMTP认证的JAVAMAIL代码 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |