您现在的位置是:首页 >

手机上怎么发送qq邮件 使用JavaMail 实现邮件发送

火烧 2023-02-11 04:51:30 1059
使用JavaMail 实现邮件发送   im ort java io * im ort java util * im ort javax mail * im ort javax mail i ter

使用JavaMail 实现邮件发送  

手机上怎么发送qq邮件 使用JavaMail 实现邮件发送
 

  import java io *; import java util *; import javax mail *; import javax mail internet *; import javax activation *;

  public class SendMail { private String from; private String to; private String username; private String password; private String subject; private String text; private File file;  public SendMail(){   }  public SendMail(String from String to String username String password){  this from=from;  this to=to;  this username=username;  this password=password; } public String getFrom() {  return from; } public void setFrom(String from) {  this from = from; } public String getTo() {  return to; } public void setTo(String to) {  this to = to; } public String getUsername() {  return username; } public void setUsername(String username) {  this username = username; } public String getPassword() {  return password; } public void setPassword(String password) {  this password = password; } public String getSubject() {  return subject; } public void setSubject(String subject) {  this subject = subject; } public String getText() {  return text; } public void setText(String text) {  this text = text; } public File getFile() {  return file; } public void setFile(File file) {  this file = file;  }  public boolean send(){  Properties props=new Properties();  props put( mail smtp host );  //props put( mail smtp host localhost );  props put( mail smtp auth true);    Session mailSession=Session getDefaultInstance(props null);    try{   Transport trans=mailSession getTransport( smtp );   nnect( username password);  // nnect();   Message newMessage=new MimeMessage(mailSession);         newMessage setSubject(subject);   newMessage setFrom(new InternetAddress(from));      /*    * 上传一个文件    * */   BodyPart fileBodyPart=new MimeBodyPart();   FileDataSource fds=new FileDataSource(file);   fileBodyPart setDataHandler(new DataHandler(fds));   fileBodyPart setFileName( a wav );      Address addressTo[] = { new InternetAddress( )};   newMessage setRecipients(Message RecipientType TO addressTo);   newMessage setText(text);      /*    * 将文件保存到Message中    * */   MimeMultipart multi = new MimeMultipart();    multi addBodyPart(fileBodyPart);   newMessage setContent(multi);

lishixinzhi/Article/program/Java/hx/201311/26077  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码