java邮件客户端代码 java邮件开发详解

用java写一个邮件发送代码

public boolean mainto()

成都创新互联公司专注于黄陂网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供黄陂营销型网站建设,黄陂网站制作、黄陂网页设计、黄陂网站官网定制、小程序制作服务,打造黄陂网络公司原创品牌,更为您提供黄陂网站排名全网营销落地服务。

{

boolean flag = true;

//建立邮件会话

Properties pro = new Properties();

pro.put("mail.smtp.host","smtp.qq.com");//存储发送邮件的服务器

pro.put("mail.smtp.auth","true"); //通过服务器验证

Session s =Session.getInstance(pro); //根据属性新建一个邮件会话

//s.setDebug(true);

//由邮件会话新建一个消息对象

MimeMessage message = new MimeMessage(s);

//设置邮件

InternetAddress fromAddr = null;

InternetAddress toAddr = null;

try

{

fromAddr = new InternetAddress(451144426+"@qq.com"); //邮件发送地址

message.setFrom(fromAddr); //设置发送地址

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

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

message.setSubject(title); //设置邮件标题

message.setText(content); //设置邮件正文

message.setSentDate(new Date()); //设置邮件日期

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

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

transport.connect("smtp.qq.com", "451144426", "密码"); //服务器地址,邮箱账号,邮箱密码

transport.sendMessage(message, message.getAllRecipients()); //发送邮件

transport.close();//关闭

}

catch (Exception e)

{

e.printStackTrace();

flag = false;//发送失败

}

return flag;

}

这是一个javaMail的邮件发送代码,需要一个mail.jar

100高分诚求:Java邮件系统源代码

你的这个要求有点离谱,如果真的要的话

建议去这个找吧,源代码都有的

求一个javaweb邮件收发系统eclipse源代码,tomcat可以运行的。

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发送邮件的5个步骤

//1、创建session

Session session = Session.getInstance(prop);

//开启Session的debug模式,这样就可以查看到程序发送Email的运行状态

session.setDebug(true);

//2、通过session得到transport对象

Transport ts = session.getTransport();

//3、使用邮箱的用户名和密码连上邮件服务器,发送邮件时,发件人需要提交邮箱的用户名和密码给smtp服务器,用户名和密码都通过验证之后才能够正常发送邮件给收件人。

ts.connect("smtp.sohu.com", "gacl", "邮箱密码");

//4、创建邮件

Message message = createSimpleMail(session);

//5、发送邮件

ts.sendMessage(message, message.getAllRecipients());

ts.close();

}

/**

* @Method: createSimpleMail

* @Description: 创建一封只包含文本的邮件

* @param session

* @return

* @throws Exception

*/

public static MimeMessage createSimpleMail(Session session)

throws Exception {

//创建邮件对象

MimeMessage message = new MimeMessage(session);

//指明邮件的发件人

message.setFrom(new InternetAddress("gacl@sohu.com"));

//指明邮件的收件人,现在发件人和收件人是一样的,那就是自己给自己发

message.setRecipient(Message.RecipientType.TO, new InternetAddress("gacl@sohu.com"));

//邮件的标题

message.setSubject("只包含文本的简单邮件");

//邮件的文本内容

message.setContent("你好啊!", "text/html;charset=UTF-8");

//返回创建好的邮件对象

return message;

}

}

求java实现邮件发送的源代码

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("发件人邮箱"); 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(邮件服务商,这是163的)","发件邮箱","发件邮箱密码"); transport.sendMessage(message,message.getAllRecipients()); transport.close(); } catch(AddressException e){ e.printStackTrace(); } catch(MessagingException e){ e.printStackTrace(); } }}

名称栏目:java邮件客户端代码 java邮件开发详解
文章路径:https://www.cdcxhl.com/article2/docopic.html

成都网站建设公司_创新互联,为您提供网站营销定制开发手机网站建设网页设计公司建站公司关键词优化

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发