国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

JavaMail發(fā)送附件的例子

2019-11-18 15:23:15
字體:
供稿:網(wǎng)友

  Here is the code to send an attachment:
  import java.util.PRoperties;
  import javax.mail.*;
  import javax.mail.internet.*;
  import javax.activation.*; public class AttachExample {
  public static void main (String args[])
  throws Exception {
  String host = args[0];
  String from = args[1];
  String to = args[2];
  String fileAttachment = args[3];
  
  // Get system properties
  Properties props = System.getProperties();
  
  // Setup mail server
  props.put("mail.smtp.host", host);
  
  // Get session
  Session session =
  Session.getInstance(props, null);
  
  // Define message
  MimeMessage message =
  new MimeMessage(session);
  message.setFrom(
  new InternetAddress(from));
  message.addRecipient(
  Message.RecipientType.TO,
  new InternetAddress(to));
  message.setSubject(
  "Hello JavaMail Attachment");
  
  // create the message part
  MimeBodyPart messageBodyPart =
  new MimeBodyPart();
  
  //fill message
  messageBodyPart.setText("Hi");
  
  Multipart multipart = new MimeMultipart();
  multipart.addBodyPart(messageBodyPart);
  
  // Part two is attachment
  messageBodyPart = new MimeBodyPart();
  DataSource source =
  new FileDataSource(fileAttachment);
  messageBodyPart.setDataHandler(
  new DataHandler(source));
  messageBodyPart.setFileName(fileAttachment);
  multipart.addBodyPart(messageBodyPart);
  
  // Put parts in message
  message.setContent(multipart);
  
  // Send the message
  Transport.send( message );
  }
  }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 上杭县| 崇州市| 洛扎县| 滨海县| 嘉峪关市| 东兴市| 义乌市| 西华县| 泸西县| 安吉县| 通江县| 台湾省| 江安县| 乡宁县| 淳安县| 长兴县| 饶阳县| 乌拉特后旗| 保康县| 云林县| 砚山县| 尉氏县| 专栏| 修武县| 南开区| 华宁县| 龙江县| 奉新县| 安义县| 忻城县| 太谷县| 临邑县| 随州市| 兰溪市| 犍为县| 屏南县| 中方县| 云林县| 抚顺县| 喜德县| 全州县|