留个脚印package mail_send_rec_byjm;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
import java.io.*;
import javax.activation.*;
public String host="smtp.163.com";
public String username="abcdefg";
public String password="abcdefg";
public String mail_head_name="this is head of this mail";
public String mail_head_value="this is head of this mail";
public String mail_to="[email protected]";
public String mail_from="[email protected]";
public String mail_subject="this is the subject of this test mail";
public String mail_body="this is the mail_body of this test mail";
void jButton1_actionPerformed(ActionEvent e) {
try
{//此段代码用来发送普通电子邮件
Properties props = new Properties();//获取系统环境
Authenticator auth = new Email_Autherticator();//进行邮件服务器用户认证
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props,auth);
//设置session,和邮件服务器进行通讯。
MimeMessage message = new MimeMessage(session);
message.setContent("Hello","text/plain");//设置邮件格式
message.setSubject(mail_subject);//设置邮件主题
message.setText(mail_body);//设置邮件正文
message.setHeader(mail_head_name,mail_head_value);//设置邮件标题
message.setSentDate(new Date());//设置邮件发送日期
Address address = new InternetAddress(mail_from,"sunxiaoming");
message.setFrom(address); //设置邮件发送者的地址
//如果要对邮件发送者进行多个参数的设置,可以用以下语句
// Address address[] = {new InternetAddress("[email protected]","sunxmatoaklet"),new InternetAddress("[email protected]","sunxmathotmail")};
// message.addFrom(address);
Address toAddress = new InternetAddress(mail_to);//设置邮件接收方的地址
message.addRecipient(Message.RecipientType.TO,toAddress);
// Address ccAddress = new InternetAddress("[email protected]");//设置邮件抄送者的地址
// message.addRecipient(Message.RecipientType.CC,ccAddress);
Transport.send(message);//发送邮件
/* // to get a specific instance from the session for your protocol.pass along the username and password
// (blank if unnecessary).send the message,and close the connection;
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host,username,password);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
*/
System.out.println("send ok!");
}
catch(Exception ex)
{
System.out.println("faild"+ex);
}
}那些smtphost,from,to等等这些没有设置好
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
import java.io.*;
import javax.activation.*;
public String host="smtp.163.com";
public String username="abcdefg";
public String password="abcdefg";
public String mail_head_name="this is head of this mail";
public String mail_head_value="this is head of this mail";
public String mail_to="[email protected]";
public String mail_from="[email protected]";
public String mail_subject="this is the subject of this test mail";
public String mail_body="this is the mail_body of this test mail";
void jButton1_actionPerformed(ActionEvent e) {
try
{//此段代码用来发送普通电子邮件
Properties props = new Properties();//获取系统环境
Authenticator auth = new Email_Autherticator();//进行邮件服务器用户认证
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props,auth);
//设置session,和邮件服务器进行通讯。
MimeMessage message = new MimeMessage(session);
message.setContent("Hello","text/plain");//设置邮件格式
message.setSubject(mail_subject);//设置邮件主题
message.setText(mail_body);//设置邮件正文
message.setHeader(mail_head_name,mail_head_value);//设置邮件标题
message.setSentDate(new Date());//设置邮件发送日期
Address address = new InternetAddress(mail_from,"sunxiaoming");
message.setFrom(address); //设置邮件发送者的地址
//如果要对邮件发送者进行多个参数的设置,可以用以下语句
// Address address[] = {new InternetAddress("[email protected]","sunxmatoaklet"),new InternetAddress("[email protected]","sunxmathotmail")};
// message.addFrom(address);
Address toAddress = new InternetAddress(mail_to);//设置邮件接收方的地址
message.addRecipient(Message.RecipientType.TO,toAddress);
// Address ccAddress = new InternetAddress("[email protected]");//设置邮件抄送者的地址
// message.addRecipient(Message.RecipientType.CC,ccAddress);
Transport.send(message);//发送邮件
/* // to get a specific instance from the session for your protocol.pass along the username and password
// (blank if unnecessary).send the message,and close the connection;
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host,username,password);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
*/
System.out.println("send ok!");
}
catch(Exception ex)
{
System.out.println("faild"+ex);
}
}那些smtphost,from,to等等这些没有设置好
解决方案 »
- jaxb写xml文件,date类型自动加上时间
- FTP 批量删除服务器文件相关
- 百分求教高手<s:file>标签关于文件上传问题
- jdbc操作SqlServer数据库出错,谁来帮我解决一下
- 刚刚接触EL表达示很迷惑!!!!求解
- MyEclipse6.0中开发struts2.0
- Jakarta-ORO库 在哪里有得下载?
- 发表下个人对struts国际化和Tiles标签库的见解,还请指正
- 昨天买了一本Thinking in JAVA(The Second Edition)中文版,感觉不错!
- bmp问题,求教
- 一个弱问题,JBuilder9中在那里能修改ejb-jar.xml文件
- 比较 好的ejb教程,用的是Blazix app server,1.5兆大的,支持ejb1.1和jsp(不可思议,太小了)馓分
我想是不是notes系统的邮件有自己比较特别的一点东西,以至于用javcmail没有办法分析notes的邮件格式呢?希望有javamail的高手或者notes高手能帮我分析一下...
String disposition = part.getDisposition();
if ( (disposition != null) &&
( (disposition.equals(Part.ATTACHMENT) ||
(disposition.equals(Part.INLINE))))) {
还是通过contentType,你自己多试试吧。
记得当时的思路就是:你不是在这出错吗,那我就在你之前加判断。