導航:首頁 > 編程語言 > java163郵箱

java163郵箱

發布時間:2023-07-04 08:27:22

java 關於郵件發送,接受地址填的是163或者QQ的,但不知道為啥總錯誤

1.自己電腦不需要配smtp,你是用163的smtp
2.553是收件人地址無法解析的錯誤,在addRecipients那一行斷點,看看toAddr傳過來的參數是不是有問題

❷ 急java 發送郵件 急!~急!~ 高手快進來幫忙看看啊!~

這是我的連續發幾封郵件的代碼。連續發是為了163郵箱的積分,^_^。你可以參考下。
package com.test;

import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendEmail extends Authenticator {
public static final String mailuser = "xianlaioy"; // 需要你的郵箱帳號(僅@符號前面的)
public static final String password = "######"; // 需要你的郵箱密碼
private Properties props;

public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailuser, password);
}

public SendEmail(){
props = new Properties();
InputStream is = null;
try {
/*當部署在web容器中時,路徑要修改
* Thread.currentThread().getContextClassLoader().getResource("").getPath();
* 得到的url是web容器中的項目下的class路徑
**/

is = new FileInputStream("src/sendemail.properties");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
props.load(is);
} catch (IOException e) {
e.printStackTrace();
}

}

/** email為接收郵箱,text為郵件正文
* @throws IOException */
public void sendEamils(String email, String text) throws IOException {
Transport transport = null;
try {
props.setProperty("mail.smtp.host", props.getProperty("mail.smtp.host"));
props.setProperty("mail.smtp.auth", props.getProperty("mail.smtp.auth"));
SendEmail auth = new SendEmail();
javax.mail.Session session = javax.mail.Session.getDefaultInstance(props,
auth);
MimeMessage message = new MimeMessage(session);
Address addressFrom = new InternetAddress(SendEmail.mailuser
+ "@163.com", "歐陽");
Address addressTo = new InternetAddress(email, "xianlai");

message.setText(text);
message.setSubject("郵件標題");
message.setFrom(addressFrom);
message.addRecipient(Message.RecipientType.TO, addressTo);

message.saveChanges();
transport = session.getTransport("smtp");
session.setDebug(true);

/*transport.connect("smtp.126.com", SendEmail.mailuser,
SendEmail.password);*/

transport.send(message);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} finally {
if (transport != null) {
try {
transport.close();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
}

public static void main(String[] args) {

Timer t = new Timer();
long delay =2*60*1000;
t.schele(new TimerTask(){
private int count=0;
private SendEmail se=new SendEmail();//作為成員變數就只會創建一個SendEmail對象。

public void run() {
//在timer的run中就必須考慮好怎樣或者什麼時候退出的問題。
//這里是用count計數的方法來考慮退出的問題的。
if(count++<1){
int i=10;
for (int j = 0; j < i; j++) {
try {
se.sendEamils("[email protected]","test"+j );
} catch (IOException e) {
e.printStackTrace();
}
}
}else {
this.cancel();
System.exit(0);
}
}}, 2000,delay);

}
}

閱讀全文

與java163郵箱相關的資料

熱點內容
android仿ios時間選擇器 瀏覽:378
見識pdf 瀏覽:81
男孩子慰菊手冊pdf 瀏覽:531
注冊表啟動項命令 瀏覽:109
89c51單片機定時器 瀏覽:687
一般不適合做程序員的適合做啥 瀏覽:923
點在多邊形內演算法 瀏覽:494
程序員下班急忙回家 瀏覽:359
安慶php全套源碼交友類型網站源碼 瀏覽:92
浪潮伺服器公司地址 瀏覽:733
密約聊天交友app怎麼賺錢 瀏覽:280
滴滴java 瀏覽:109
phpexpires 瀏覽:218
matlab編程用什麼語言 瀏覽:70
php查找字元是否存在 瀏覽:701
可編程函數發生器 瀏覽:881
單片機正極接地視頻 瀏覽:67
利用python爬火車票 瀏覽:375
androidaidl如何工作 瀏覽:855
第三胸椎壓縮骨折什麼症狀 瀏覽:506