菜鸟请教一个javamail的问题,在线等待高手赐教。。。。顺便问一下,如何给分。。。。。 evilegend(本来无一物,何处惹尘埃) 师傅,不好意思再打扰一下,自己怎么做mail服务器呢,谢谢您。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先我们要搞清楚,为什么要身份验证,和在哪儿身份验证。身份验证和javamail无关,它是根据邮件服务器来决定的,如果邮件服务器上的设置是需要身份验证,这在调用javamail程序发送/接受邮件时就需要设置其 “身份验证”= true;自己怎么做mail服务器就说来话长了,首先你要找一台具有公共IP的主机,然后装上操作系统,邮件服务软件,......不同的操作系统和不同的邮件服务软件配置不同,需要具体分析。详情可以在google上search一下。 给你一个例子。package jmail;import com.sun.mail.imap.Utility;import javax.mail.internet.*;import javax.mail.Session;import javax.mail.MessagingException;import javax.mail.Message;import javax.mail.Transport;import javax.activation.FileDataSource;import javax.activation.DataHandler;import java.util.Properties;import java.util.Date;import java.util.ArrayList;import java.io.UnsupportedEncodingException;/** * Created by IntelliJ IDEA. * User: Administrator * Date: 2004/12/01 * Time: 13:27:40 * To change this template use File | Settings | File Templates. */public class SendJavaMail { public SendJavaMail() { } public static void main(String[] args){ try { Properties properties = System.getProperties(); properties.put("mail.smtp.host","192.168.0.1"); Session sendSession = Session.getInstance(properties,null); System.out.println(sendSession.getProperty("mail.smtp.host")); InternetAddress[] mailTo = InternetAddress.parse("[email protected]"); Message message = new MimeMessage(sendSession); message.setFrom(new InternetAddress("[email protected]")); message.setRecipients(Message.RecipientType.TO,mailTo); message.setSubject("This message is sent by javamail"); MimeMultipart multipart = new MimeMultipart(); MimeBodyPart bodyPart = new MimeBodyPart(); bodyPart.setContent("This is a mail with file","text/html;charset=GB2312"); multipart.addBodyPart(bodyPart); ArrayList attachment = new ArrayList(); attachment.add(0,"picture2.jpg"); attachment.add(1,"picture3.jpg"); attachment.add(2,"picture4.jpg"); attachment.add(3,"picture5.jpg"); message.setContent(multipart); message.setSentDate(new Date()); Transport transport = sendSession.getTransport("smtp"); transport.connect("server","",""); System.out.println(transport.toString()); transport.sendMessage(message,mailTo); transport.close(); System.out.println("The mail has sent"); } catch (AddressException e) { e.printStackTrace(); } catch (MessagingException me){ me.printStackTrace(); } }} 先谢了,, 我这边有专门的邮件服务器的, 不过是公司出钱租来用的, 因为不是很清楚这些东西, 我试着发过用javaMail 但是提示邮件host 无效, 云计算 shark 工作流 xml查询问题 在 深 圳 计 算 机 行 业 协 会 培训JAVA的请进来!!! 大家在开发Struts中,除了包含标签文件外,还会在程序中用道多少<% %>符号? jdbc:oracle:thin:@localhost thin是什么含义,还有其他的方式吗? 大家推荐几本学习J2EE的好书。 EJB-QL的问题很奇怪, 好多问题啊,请各位帮帮忙 Software caused connection abort: socket write error 求助:jdom该如何配置? 如何向SQLSERVER2000插入\修改\保存数据(向各位请教)
自己怎么做mail服务器就说来话长了,首先你要找一台具有公共IP的主机,然后装上操作系统,邮件服务软件,......不同的操作系统和不同的邮件服务软件配置不同,需要具体分析。详情可以在google上search一下。
package jmail;
import com.sun.mail.imap.Utility;import javax.mail.internet.*;
import javax.mail.Session;
import javax.mail.MessagingException;
import javax.mail.Message;
import javax.mail.Transport;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;
import java.util.Properties;
import java.util.Date;
import java.util.ArrayList;
import java.io.UnsupportedEncodingException;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2004/12/01
* Time: 13:27:40
* To change this template use File | Settings | File Templates.
*/
public class SendJavaMail { public SendJavaMail() {
}
public static void main(String[] args){
try {
Properties properties = System.getProperties();
properties.put("mail.smtp.host","192.168.0.1");
Session sendSession = Session.getInstance(properties,null);
System.out.println(sendSession.getProperty("mail.smtp.host"));
InternetAddress[] mailTo = InternetAddress.parse("[email protected]");
Message message = new MimeMessage(sendSession);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,mailTo);
message.setSubject("This message is sent by javamail");
MimeMultipart multipart = new MimeMultipart();
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent("This is a mail with file","text/html;charset=GB2312");
multipart.addBodyPart(bodyPart);
ArrayList attachment = new ArrayList();
attachment.add(0,"picture2.jpg");
attachment.add(1,"picture3.jpg");
attachment.add(2,"picture4.jpg");
attachment.add(3,"picture5.jpg");
message.setContent(multipart);
message.setSentDate(new Date());
Transport transport = sendSession.getTransport("smtp"); transport.connect("server","","");
System.out.println(transport.toString());
transport.sendMessage(message,mailTo);
transport.close();
System.out.println("The mail has sent");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException me){
me.printStackTrace();
}
}
}