public boolean mainto()
成都創(chuàng)新互聯(lián)公司專注于黃陂網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供黃陂營銷型網(wǎng)站建設(shè),黃陂網(wǎng)站制作、黃陂網(wǎng)頁設(shè)計(jì)、黃陂網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造黃陂網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供黃陂網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
{
boolean flag = true;
//建立郵件會(huì)話
Properties pro = new Properties();
pro.put("mail.smtp.host","smtp.qq.com");//存儲(chǔ)發(fā)送郵件的服務(wù)器
pro.put("mail.smtp.auth","true"); //通過服務(wù)器驗(yàn)證
Session s =Session.getInstance(pro); //根據(jù)屬性新建一個(gè)郵件會(huì)話
//s.setDebug(true);
//由郵件會(huì)話新建一個(gè)消息對(duì)象
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ù)器地址,郵箱賬號(hào),郵箱密碼
transport.sendMessage(message, message.getAllRecipients()); //發(fā)送郵件
transport.close();//關(guān)閉
}
catch (Exception e)
{
e.printStackTrace();
flag = false;//發(fā)送失敗
}
return flag;
}
這是一個(gè)javaMail的郵件發(fā)送代碼,需要一個(gè)mail.jar
你的這個(gè)要求有點(diǎn)離譜,如果真的要的話
建議去這個(gè)找吧,源代碼都有的
package me.gacl.main;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Sendmail {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Properties prop = new Properties();
prop.setProperty("mail.host", "smtp.sohu.com");
prop.setProperty("mail.transport.protocol", "smtp");
prop.setProperty("mail.smtp.auth", "true");
//使用JavaMail發(fā)送郵件的5個(gè)步驟
//1、創(chuàng)建session
Session session = Session.getInstance(prop);
//開啟Session的debug模式,這樣就可以查看到程序發(fā)送Email的運(yùn)行狀態(tài)
session.setDebug(true);
//2、通過session得到transport對(duì)象
Transport ts = session.getTransport();
//3、使用郵箱的用戶名和密碼連上郵件服務(wù)器,發(fā)送郵件時(shí),發(fā)件人需要提交郵箱的用戶名和密碼給smtp服務(wù)器,用戶名和密碼都通過驗(yàn)證之后才能夠正常發(fā)送郵件給收件人。
ts.connect("smtp.sohu.com", "gacl", "郵箱密碼");
//4、創(chuàng)建郵件
Message message = createSimpleMail(session);
//5、發(fā)送郵件
ts.sendMessage(message, message.getAllRecipients());
ts.close();
}
/**
* @Method: createSimpleMail
* @Description: 創(chuàng)建一封只包含文本的郵件
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createSimpleMail(Session session)
throws Exception {
//創(chuàng)建郵件對(duì)象
MimeMessage message = new MimeMessage(session);
//指明郵件的發(fā)件人
message.setFrom(new InternetAddress("gacl@sohu.com"));
//指明郵件的收件人,現(xiàn)在發(fā)件人和收件人是一樣的,那就是自己給自己發(fā)
message.setRecipient(Message.RecipientType.TO, new InternetAddress("gacl@sohu.com"));
//郵件的標(biāo)題
message.setSubject("只包含文本的簡單郵件");
//郵件的文本內(nèi)容
message.setContent("你好啊!", "text/html;charset=UTF-8");
//返回創(chuàng)建好的郵件對(duì)象
return message;
}
}
import java.util.*;
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(); } }}