欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java按鍵發(fā)郵件代碼 java按鍵發(fā)郵件代碼怎么發(fā)

求java實現(xiàn)郵件發(fā)送的源代碼

import java.util.*;

站在用戶的角度思考問題,與客戶深入溝通,找到峰峰礦網(wǎng)站設(shè)計與峰峰礦網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站制作、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋峰峰礦地區(qū)。

import javax.mail.*;import javax.mail.internet.*;

public class JMail {

public void SendMail(String Topic,String Content){ Properties props=new Properties(); props.put("mail.smtp.host","smtp.163.com"); props.put("mail.smtp.auth","true"); Session s=Session.getInstance(props); s.setDebug(false); MimeMessage message=new MimeMessage(s); MimeMultipart mp=new MimeMultipart(); BodyPart body = new MimeBodyPart(); InternetAddress from; InternetAddress to; try{ from=new InternetAddress("發(fā)件人郵箱"); message.setFrom(from); to = new InternetAddress("收件人郵箱"); message.setRecipient(Message.RecipientType.TO,to); message.setSubject(Topic,"utf-8"); body.setContent(Content, "text/html;charset=utf-8"); mp.addBodyPart(body); message.setContent(mp); message.setSentDate(new Date()); message.saveChanges(); Transport transport=s.getTransport("smtp"); transport.connect("smtp.163.com(郵件服務(wù)商,這是163的)","發(fā)件郵箱","發(fā)件郵箱密碼"); transport.sendMessage(message,message.getAllRecipients()); transport.close(); } catch(AddressException e){ e.printStackTrace(); } catch(MessagingException e){ e.printStackTrace(); } }}

用java寫一個郵件發(fā)送代碼

public boolean mainto()

{

boolean flag = true;

//建立郵件會話

Properties pro = new Properties();

pro.put("mail.smtp.host","smtp.qq.com");//存儲發(fā)送郵件的服務(wù)器

pro.put("mail.smtp.auth","true"); //通過服務(wù)器驗證

Session s =Session.getInstance(pro); //根據(jù)屬性新建一個郵件會話

//s.setDebug(true);

//由郵件會話新建一個消息對象

MimeMessage message = new MimeMessage(s);

//設(shè)置郵件

InternetAddress fromAddr = null;

InternetAddress toAddr = null;

try

{

fromAddr = new InternetAddress(451144426+"@qq.com"); //郵件發(fā)送地址

message.setFrom(fromAddr); //設(shè)置發(fā)送地址

toAddr = new InternetAddress("12345367@qq.com"); //郵件接收地址

message.setRecipient(Message.RecipientType.TO, toAddr); //設(shè)置接收地址

message.setSubject(title); //設(shè)置郵件標(biāo)題

message.setText(content); //設(shè)置郵件正文

message.setSentDate(new Date()); //設(shè)置郵件日期

message.saveChanges(); //保存郵件更改信息

Transport transport = s.getTransport("smtp");

transport.connect("smtp.qq.com", "451144426", "密碼"); //服務(wù)器地址,郵箱賬號,郵箱密碼

transport.sendMessage(message, message.getAllRecipients()); //發(fā)送郵件

transport.close();//關(guān)閉

}

catch (Exception e)

{

e.printStackTrace();

flag = false;//發(fā)送失敗

}

return flag;

}

這是一個javaMail的郵件發(fā)送代碼,需要一個mail.jar

java后端代碼實現(xiàn)發(fā)送郵件但是有時候沒響應(yīng)

java后端代碼實現(xiàn)發(fā)送郵件但是有時候沒響應(yīng)是jar包的問題。根據(jù)查詢相關(guān)公開信息:要確保郵箱已經(jīng)開啟了POP3、SMTP等服務(wù),開啟之后,一定要生成授權(quán)碼,上面的郵箱名和密碼。

如何使用Java發(fā)送qq郵件

方法:

1.前提準(zhǔn)備工作:

首先,郵件的發(fā)送方要開啟POP3 和SMTP服務(wù)--即發(fā)送qq郵件的賬號要開啟POP3 和SMTP服務(wù)

2.開啟方法:

登陸qq郵箱

3.點擊 設(shè)置

4.點擊—-賬戶

5.找到:POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務(wù) —點擊開啟

6.送短信 —–點擊確定

7.稍等一會,很得到一個授權(quán)碼! –注意:這個一定要記住,一會用到

8.點擊保存修改 —OK 完成

9.java 測試代碼:

package cn.cupcat.test;

import java.util.Properties;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.AddressException;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMessage.RecipientType;

public class SendmailUtil {

public static void main(String[] args) throws AddressException, MessagingException {

Properties properties = new Properties();

properties.put("mail.transport.protocol", "smtp");// 連接協(xié)議

properties.put("mail.smtp.host", "smtp.qq.com");// 主機(jī)名

properties.put("mail.smtp.port", 465);// 端口號

properties.put("mail.smtp.auth", "true");

properties.put("mail.smtp.ssl.enable", "true");//設(shè)置是否使用ssl安全連接 ---一般都使用

properties.put("mail.debug", "true");//設(shè)置是否顯示debug信息 true 會在控制臺顯示相關(guān)信息

//得到回話對象

Session session = Session.getInstance(properties);

// 獲取郵件對象

Message message = new MimeMessage(session);

//設(shè)置發(fā)件人郵箱地址

message.setFrom(new InternetAddress("123456789@qq.com"));

//設(shè)置收件人地址 message.setRecipients( RecipientType.TO, new InternetAddress[] { new InternetAddress("987654321@qq.com") });

//設(shè)置郵件標(biāo)題

message.setSubject("這是第一封Java郵件");

//設(shè)置郵件內(nèi)容

message.setText("內(nèi)容為: 這是第一封java發(fā)送來的郵件。");

//得到郵差對象

Transport transport = session.getTransport();

//連接自己的郵箱賬戶

transport.connect("123456789@qq.com", "vvctybgbvvophjcj");//密碼為剛才得到的授權(quán)碼

//發(fā)送郵件 transport.sendMessage(message, message.getAllRecipients());

}

}

10.運行就會發(fā)出郵件了。。。。

下面是我收到郵件的截圖,當(dāng)然我把源碼中的郵件地址都是修改了,不是真實的,你們測試的時候,可以修改能你們自己的郵箱。最后,祝你也能成功,如果有什么問題,可以一起討論!

注意事項

得到的授權(quán)碼一定要保存好,程序中要使用

網(wǎng)站題目:java按鍵發(fā)郵件代碼 java按鍵發(fā)郵件代碼怎么發(fā)
鏈接地址:http://www.chinadenli.net/article16/dddoodg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號網(wǎng)站內(nèi)鏈品牌網(wǎng)站設(shè)計用戶體驗搜索引擎優(yōu)化Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)