java mail发送附件抄送_修改后可以发送附件、抄送、密送的java

/*

*Author:tyfun

*DateTime:2003.01.09

*Package:com.westarsoft.function

*/

http://www.gaodaima.com/42580.html修改后可以发送附件、抄送、密送的java

package com.westarsoft.function;

import java.util.*;

import java.io.*;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;

public class SendMail {

private String SMTPServer = new String();

private String from = new String();

private String subject = new String();

private String content = new String();

private String user = new String();

private String password = new String();

private String fileAttachment = new String();

public String getSMTPServer() {

return SMTPServer;

}

public void setSMTPServer(String SMTPServer) {

this.SMTPServer = SMTPServer;

}

public String getFrom() {

return from;

}

public void setFrom(String from) {

this.from = from;

}

public String getSubject() {

return subject;

}

public void setSubject(String subject) {

this.subject = subject;

}

public String getContent() {

return content;

}

public void setContent(String content) {

this.content = content;

}

public String getUser() {

return user;

}

public void setUser(String user) {

this.user = user;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getFileAttachment() {

return fileAttachment;

}

public void setFileAttachment(String fileAttachment) {

this.fileAttachment = fileAttachment;

}

public void sendMailTo(String to,String cc,String bcc) {

try {

Properties props = new Properties();

Session sendMailSession;

Store store;

Transport transport;

sendMailSession = Session.getInstance(props, null);

props.put("mail.smtp.host", SMTPServer);

MimeMessage newMessage = new MimeMessage(sendMailSession);

newMessage.setFrom(new InternetAddress(from));

newMessage.setSubject(subject);

newMessage.setSentDate(new Date());

/*

StringTokenizer tokenTO = new StringTokenizer(to, ",");

InternetAddress[] addrArrTO = new InternetAddress[tokenTO.countTokens()];

int i = 0;

while(tokenTO.hasMoreTokens()) {

addrArrTO[i] = new InternetAddress(tokenTO.nextToken().toString());

i++;

}

*/

transport = sendMailSession.getTransport("smtp");

transport.connect(SMTPServer, user, password);

//newMessage.setRecipients(Message.RecipientType.TO, addrArrTO);

newMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));

newMessage.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));

newMessage.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc));

MimeBodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setText(content);

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(fileAttachment);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName(fileAttachment);

multipart.addBodyPart(messageBodyPart);

newMessage.setContent(multipart);

transport.send(newMessage);

}

catch(Exception e) {

System.out.println(e);

}

}

}

if(request.getMethod().equals("POST")) {

SendMail mail = new SendMail();

mail.setSMTPServer("200.1.1.157");

mail.setUser("lint");

mail.setPassword("30320");

mail.setFrom(request.getParameter("from"));

mail.setSubject(request.getParameter("subject"));

mail.setContent(request.getParameter("content"));

mail.setFileAttachment(request.getParameter("filename"));

mail.sendMailTo(request.getParameter("to"),request.getParameter("cc"),request.getParameter("bcc"));

}

%>

欢迎大家阅读《修改后可以发送附件、抄送、密送的java》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码

e7ce419cf2d6ad34d01da2ceb8829eed.png

微信 赏一包辣条吧~

023a57327877fb4402bcc76911ec18ea.png

支付宝 赏一听可乐吧~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值