当前位置: 技术问答>java相关
javamail 我搞不定了,高人救命!在线等待立即送分!急急急急急急急急急急急急急急急急!
来源: 互联网 发布时间:2015-07-15
本文导语: 我想向我的163信箱里发送邮件,可是怎么也不行,不知何故??? import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import java.util.*; public class mymail extends Authenticator { String userName,password; publ...
我想向我的163信箱里发送邮件,可是怎么也不行,不知何故???
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;
public class mymail extends Authenticator {
String userName,password;
public mymail(String user,String pass) {
super();
userName=new String(user);
password=new String(pass);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName,password);
}
public static void main(String[] args){
try{
Properties props=new Properties();
props.put("mail.host","smtp.163.net");
props.put("mail.transport.protocol","smtp");
//props.put("mail.transport.port","");
props.put("mail.pop3.auth","true"); //这行一定要有
mymail mm=new mymail("zmrljl","zmrljl");
//SmtpAuthenticator sa=new SmtpAuthenticator("zmrljl","fcyljl");
Session mailConnection=Session.getInstance(props,mm);
mailConnection.setDebug(false);
Transport tr=mailConnection.getTransport("smtp");
Message msg=new MimeMessage(mailConnection);
Address bill=new InternetAddress("fcyljlyy@sohu.com");
Address elliotte=new InternetAddress("zmrljl@yeah.net");
msg.setContent("resistansce is futile ,tyou wiil be assistant!","text/plain");
msg.setFrom(bill);
msg.setRecipient(Message.RecipientType.TO,elliotte);
msg.setSubject("you must ok");
tr.send(msg);
}
catch(Exception e){
e.printStackTrace() ;
}
}
}
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;
public class mymail extends Authenticator {
String userName,password;
public mymail(String user,String pass) {
super();
userName=new String(user);
password=new String(pass);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName,password);
}
public static void main(String[] args){
try{
Properties props=new Properties();
props.put("mail.host","smtp.163.net");
props.put("mail.transport.protocol","smtp");
//props.put("mail.transport.port","");
props.put("mail.pop3.auth","true"); //这行一定要有
mymail mm=new mymail("zmrljl","zmrljl");
//SmtpAuthenticator sa=new SmtpAuthenticator("zmrljl","fcyljl");
Session mailConnection=Session.getInstance(props,mm);
mailConnection.setDebug(false);
Transport tr=mailConnection.getTransport("smtp");
Message msg=new MimeMessage(mailConnection);
Address bill=new InternetAddress("fcyljlyy@sohu.com");
Address elliotte=new InternetAddress("zmrljl@yeah.net");
msg.setContent("resistansce is futile ,tyou wiil be assistant!","text/plain");
msg.setFrom(bill);
msg.setRecipient(Message.RecipientType.TO,elliotte);
msg.setSubject("you must ok");
tr.send(msg);
}
catch(Exception e){
e.printStackTrace() ;
}
}
}
|
props.put("mail.pop3.auth","true"); //这行一定要有
改成:
props.put("mail.smtp.auth","true"); //这行一定要有
改成:
props.put("mail.smtp.auth","true"); //这行一定要有
|
好像是不能自己给自己发信,我以前也试过。
|
用163 ,yeah 发信需要用户验证的
|
static class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("wen-jian", "");
}
}
public static void send(String smtpServer, String to, String from
, String subject, String body)
{
SimpleSender SimpleSender1 = new SimpleSender();
try
{
Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
MyAuthenticator auth = new MyAuthenticator();
Session session = Session.getDefaultInstance(props,auth);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
// -- We could include CC recipients too --
// if (cc != null)
// msg.setRecipients(Message.RecipientType.CC
// ,InternetAddress.parse(cc, false));
// -- Set the subject and body text --
msg.setSubject(subject);
msg.setText(body);
// -- Set some other header information --
msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
// -- Send the message --
Transport transport = session.getTransport("smtp");
Transport.send(msg);
System.out.println("Message sent OK.");
Store store = session.getStore("pop3");
store.connect("smtp.163.net", "wen-jian","123456");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
System.out.println(((MimeMessage)message[0]).getContent());
}
这个是我试过的
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("wen-jian", "");
}
}
public static void send(String smtpServer, String to, String from
, String subject, String body)
{
SimpleSender SimpleSender1 = new SimpleSender();
try
{
Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
MyAuthenticator auth = new MyAuthenticator();
Session session = Session.getDefaultInstance(props,auth);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
// -- We could include CC recipients too --
// if (cc != null)
// msg.setRecipients(Message.RecipientType.CC
// ,InternetAddress.parse(cc, false));
// -- Set the subject and body text --
msg.setSubject(subject);
msg.setText(body);
// -- Set some other header information --
msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
// -- Send the message --
Transport transport = session.getTransport("smtp");
Transport.send(msg);
System.out.println("Message sent OK.");
Store store = session.getStore("pop3");
store.connect("smtp.163.net", "wen-jian","123456");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
System.out.println(((MimeMessage)message[0]).getContent());
}
这个是我试过的
|
props.put("mail.smtp.auth","true");
mymail mm=new mymail("zmrljl","zmrljl");
你发信的地址是zmrljl吗?
你发信的地址的密码也是zmrljl吗?
要人证的话,就需要实际的邮箱用户和密码!
mymail mm=new mymail("zmrljl","zmrljl");
你发信的地址是zmrljl吗?
你发信的地址的密码也是zmrljl吗?
要人证的话,就需要实际的邮箱用户和密码!
|
是不是用的代理服务器啊?
另外,可能跟网络设置有关的。
另外,可能跟网络设置有关的。
|
163好像也需要SMTP认证的,你找一个不需要认证的邮箱试试看。
|
是啊,我原来用不认证的试了一下,没问题,又换163,用我自己的信箱来试,成功发到了我公司的信箱中。
所以我才跟你说……
我的msn:sharetop@hotmail.com
这事如果急,可以与我讨论
所以我才跟你说……
我的msn:sharetop@hotmail.com
这事如果急,可以与我讨论
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。