快速业务通道

Java发送邮件 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-17
message.setSubject(getTitle());//设置主题 Multipart multipart = new MimeMultipart(); BodyPart contentPart = new MimeBodyPart(); contentPart.setContent(this.getSendtext(), "text/html;charset=GBK");//设置信件内容 multipart. addBodyPart(contentPart); if(getAttachPath() != null && getAttachName() != null){ BodyPart attachmentPart= new MimeBodyPart(); DataSource source = new FileDataSource(getAttachPath()); attachmentPart.setDataHandler(new DataHandler(source)); BASE64Encoder enc = new BASE64Encoder(); attachmentPart.setFileName("=?GBK?B?"+enc.encode(getAttachName().getBytes())+"?="); multipart.addBodyPart(attachmentPart); } message.setContent(multipart); message.saveChanges(); Transport transport = session.getTransport("smtp"); transport.connect(host, getUsername(), getPassword()); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } private String host = null; //邮件服务器 private String fromAddr = null; //发送邮件地址 private String toAddr = null; //接收邮件地址 private String username = null; //发送邮件用户名 private String password = null; //发送邮件密码 private String title = null; //邮件标题 private String attachPath = null; //邮件附件路径 private String attachName = null; //邮件附件名 private String sendtext = null; //邮件内容 private String[] MutliTo = null; //群发用户 public String[] getMutliTo() { return MutliTo; } public void setMutliTo(String[] mutliTo) { MutliTo = mutliTo; } public String getSendtext() { return sendtext; } public void setSendtext(String sendtext) { this.sendtext = sendtext; } public String getHost() { return host; } public void setHost(String host) { this.host = host; } public String getFromAddr() { return fromAddr; } public void setFromAddr(String fromAddr) { this.fromAddr = fromAddr; } public String getToAddr() { return toAddr; } public void setToAddr(String toAddr) { this.toAddr = toAddr; } 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 getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAttachPath() { return attachPath; } public void setAttachPath(String attachPath) { this.attachPath = attachPath; } public String getAttachName() { return attachName; } public void setAttachName(String attachName) { this.attachName = attachName;

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号