
这是我这样做的代码:
import javax.mail.*;import javax.mail.internet.*;// Set up the SMTP server.java.util.Properties props = new java.util.Properties();props.put("mail.smtp.host", "smtp.myisp.com");Session session = Session.getDefaultInstance(props, null);// Construct the messageString to = "you@you.com";String from = "me@me.com";String subject = "Hello";Message msg = new MimeMessage(session);try { msg.setFrom(new InternetAddress(from)); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); msg.setSubject(subject); msg.setText("Hi,nnHow are you?"); // Send the message. Transport.send(msg);} catch (MessagingException e) { // Error.}您可以在此处从Sun获得JavaMail库:http :
//java.sun.com/products/javamail/
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)