如何使用Java发送电子邮件?

如何使用Java发送电子邮件?,第1张

如何使用Java发送电子邮件?

这是我这样做的代码

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/



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5000326.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存