如果你認為沒有必要設置MAIL服務器
說明
身份認證的javabean package netcard; /** *SendEcard
import java
import javax
import javax
import javax
public class SendEcard {
private String tomail;
private String frommail;
private String subject;
private String content;
private String imagecard;
String smtp=
public SendEcard()
{
}
public String getTomail()
{
return tomail;
}
public void setTomail(String tomail)
{
this
}
public String getFrommail() {
return frommail;
}
public void setFrommail(String frommail) {
this
} public String getSubject() {
return subject;
}
public void setSubject(String subject)
{
this
}
public String getContent() {
return content;
}
public void setContent(String content)
{
ntent = content;
}
public String getImagecard()
{
return imagecard;
}
public void setImagecard(String imagecard)
{
this
}
public boolean sendMail(){
try{
Properties p=System
p
p
Session session=Session
MimeMessage msg=new MimeMessage(session);
msg
InternetAddress from=new InternetAddress(frommail);
msg
InternetAddress[] address = {
new InternetAddress(tomail)};
msg
msg
Multipart mp = new MimeMultipart();
MimeBodyPart mbp=new MimeBodyPart();
FileDataSource fds=new FileDataSource(文件路徑);
//得到附件本身並至入BodyPart
mbp
//得到文件名同樣至入BodyPart
mbp
mp
msg
Transport
return true;
}catch(AddressException addr_e){
System
return false;
}catch(MessagingException msg_e){
System
return false;
}
}
}
package netcard; /** *Email_ca
public class Email_ca extends javax
private String user=null; private String pwd=null;
public Email_ca(){
super();
}
public void setUser(String user){
this
}
public void setPwd(String pwd){
this
}
public Email_ca(String user
super();
setUser(user);
setPwd(pwd);
}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user
}
}
至此你就可以利用免費郵箱服務器進行郵件發送!
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26972.html