导航:首页 > 编程语言 > java邮件内容

java邮件内容

发布时间:2025-09-20 11:43:23

1. java mail中Authenticator这个类到底有什么作用

首先,要矫正你的一个错误,Authenticator这个类是在Java.net.*;中的。
Authenticator 类表示懂得如何获得网络连接验证的对象。通常,它通过提示用户输入信息来完成此操作。

2. 怎么写java技术邮件

写作思路:一封邮件的基本内容通常分为三部分:收件人、主题、正文。主题要突出邮件的主旨,要让别人一看到这个主题就能大概知道你想传递的是什么事情。意思明确,引人注目。

如下:

尊敬的xx公司领导:

建立本站的主要目的是为了通过网络应接一些与java技术相关的一些项目,例如基于j2ee的jsp、struts等开发web网站;或基于j2se开发应用软件件。

建立本站除了希望增加接项目和寻找编程相关的兼职的途径外,还希望能通过本网站结交更多的软件开发人士,交流软件开发知识和java编程技术,更好地提高自已的软件开发技术。

此致

敬礼!

3. 如何使用Java发送qq邮件

方法:

1.前提准备工作:
首先,邮件的发送方要开启POP3 和SMTP服务--即发送qq邮件的账号要开启POP3 和SMTP服务

2.开启方法:
登陆qq邮箱
3.点击 设置

4.点击—-账户

5.找到:POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务 —点击开启

6.送短信 —–点击确定

7.稍等一会,很得到一个授权码! –注意:这个一定要记住,一会用到

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");// 连接协议
properties.put("mail.smtp.host", "smtp.qq.com");// 主机名
properties.put("mail.smtp.port", 465);// 端口号
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.ssl.enable", "true");//设置是否使用ssl安全连接 ---一般都使用
properties.put("mail.debug", "true");//设置是否显示debug信息 true 会在控制台显示相关信息
//得到回话对象
Session session = Session.getInstance(properties);
// 获取邮件对象
Message message = new MimeMessage(session);
//设置发件人邮箱地址
message.setFrom(new InternetAddress("[email protected]"));
//设置收件人地址 message.setRecipients( RecipientType.TO, new InternetAddress[] { new InternetAddress("[email protected]") });
//设置邮件标题
message.setSubject("这是第一封Java邮件");
//设置邮件内容
message.setText("内容为: 这是第一封java发送来的邮件。");
//得到邮差对象
Transport transport = session.getTransport();
//连接自己的邮箱账户
transport.connect("[email protected]", "vvctybgbvvophjcj");//密码为刚才得到的授权码
//发送邮件 transport.sendMessage(message, message.getAllRecipients());
}
}
10.运行就会发出邮件了。。。。
下面是我收到邮件的截图,当然我把源码中的邮件地址都是修改了,不是真实的,你们测试的时候,可以修改能你们自己的邮箱。最后,祝你也能成功,如果有什么问题,可以一起讨论!

注意事项

得到的授权码一定要保存好,程序中要使用

4. java 代码发邮件怎么添加附件

实现java发送邮件的过程大体有以下几步:

准备一个properties文件,该文件中存放SMTP服务器地址等参数。

利用properties创建一个Session对象

利用Session创建Message对象,然后设置邮件主题和正文

利用Transport对象发送邮件

需要的jar有2个:activation.jar和mail.jar发送附件,需要用到Multipart对象。

importjava.io.File;
importjava.io.IOException;
importjava.io.InputStream;
importjava.util.Properties;

importjavax.activation.DataHandler;
importjavax.activation.DataSource;
importjavax.activation.FileDataSource;
importjavax.mail.BodyPart;
importjavax.mail.Message;
importjavax.mail.MessagingException;
importjavax.mail.Multipart;
importjavax.mail.Session;
importjavax.mail.Transport;
importjavax.mail.internet.InternetAddress;
importjavax.mail.internet.MimeBodyPart;
importjavax.mail.internet.MimeMessage;
importjavax.mail.internet.MimeMultipart;
importjavax.mail.internet.MimeUtility;

{
privateMimeMessagemessage;
privateSessionsession;
privateTransporttransport;

privateStringmailHost="";
privateStringsender_username="";
privateStringsender_password="";

privatePropertiesproperties=newProperties();

/*
*初始化方法
*/
publicJavaMailWithAttachment(booleandebug){
InputStreamin=JavaMailWithAttachment.class.getResourceAsStream("MailServer.properties");
try{
properties.load(in);
this.mailHost=properties.getProperty("mail.smtp.host");
this.sender_username=properties.getProperty("mail.sender.username");
this.sender_password=properties.getProperty("mail.sender.password");
}catch(IOExceptione){
e.printStackTrace();
}

session=Session.getInstance(properties);
session.setDebug(debug);//开启后有调试信息
message=newMimeMessage(session);
}

/**
*发送邮件
*
*@paramsubject
*邮件主题
*@paramsendHtml
*邮件内容
*@paramreceiveUser
*收件人地址
*@paramattachment
*附件
*/
publicvoiddoSendHtmlEmail(Stringsubject,StringsendHtml,StringreceiveUser,Fileattachment){
try{
//发件人
InternetAddressfrom=newInternetAddress(sender_username);
message.setFrom(from);

//收件人
InternetAddressto=newInternetAddress(receiveUser);
message.setRecipient(Message.RecipientType.TO,to);

//邮件主题
message.setSubject(subject);

//向multipart对象中添加邮件的各个部分内容,包括文本内容和附件
Multipartmultipart=newMimeMultipart();

//添加邮件正文
BodyPartcontentPart=newMimeBodyPart();
contentPart.setContent(sendHtml,"text/html;charset=UTF-8");
multipart.addBodyPart(contentPart);

//添加附件的内容
if(attachment!=null){
BodyPartattachmentBodyPart=newMimeBodyPart();
DataSourcesource=newFileDataSource(attachment);
attachmentBodyPart.setDataHandler(newDataHandler(source));

//网上流传的解决文件名乱码的方法,其实用MimeUtility.encodeWord就可以很方便的搞定
//这里很重要,通过下面的Base64编码的转换可以保证你的中文附件标题名在发送时不会变成乱码
//sun.misc.BASE64Encoderenc=newsun.misc.BASE64Encoder();
//messageBodyPart.setFileName("=?GBK?B?"+enc.encode(attachment.getName().getBytes())+"?=");

//MimeUtility.encodeWord可以避免文件名乱码
attachmentBodyPart.setFileName(MimeUtility.encodeWord(attachment.getName()));
multipart.addBodyPart(attachmentBodyPart);
}

//将multipart对象放到message中
message.setContent(multipart);
//保存邮件
message.saveChanges();

transport=session.getTransport("smtp");
//smtp验证,就是你用来发邮件的邮箱用户名密码
transport.connect(mailHost,sender_username,sender_password);
//发送
transport.sendMessage(message,message.getAllRecipients());

System.out.println("sendsuccess!");
}catch(Exceptione){
e.printStackTrace();
}finally{
if(transport!=null){
try{
transport.close();
}catch(MessagingExceptione){
e.printStackTrace();
}
}
}
}

publicstaticvoidmain(String[]args){
JavaMailWithAttachmentse=newJavaMailWithAttachment(true);
Fileaffix=newFile("c:\测试-test.txt");
se.doSendHtmlEmail("邮件主题","邮件内容","[email protected]",affix);//
}
}
阅读全文

与java邮件内容相关的资料

热点内容
单片机的p10 浏览:350
铣外圆格式编程视频 浏览:237
挂壁式空调压缩机 浏览:699
通信服务器是什么意思 浏览:385
私有云与服务器有什么区别 浏览:371
设计源码是什么 浏览:507
nioslinux 浏览:452
程序员用多大笔记本 浏览:672
游戏脚本高级编程英文版 浏览:507
从不懂编程到成一个大神 浏览:407
pdf转换器永久破解版 浏览:338
java邮件内容 浏览:129
如何正确地解压 浏览:190
f盘里的图片文件夹可以删吗 浏览:12
宠物大进化源码 浏览:748
英雄联盟手游微信区安卓怎么扫码 浏览:715
如何买云服务器价格对比 浏览:652
简述linux源码安装步骤 浏览:96
单片机张毅刚答案 浏览:676
究极风暴3压缩包 浏览:533