import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
* Created by 马洋 on 2021/10/21 16:36
public class EmailSend {
* @param MailTitle 邮件标题
* @param MailContent 邮件内容
* @param Sender 邮件发送人
* @param MailReceiver 邮件接收人(可多个)
* @param AuthorizationCode 邮件发送人邮箱授权码 cizojpskiplhbfhb
public static void send(String MailTitle,String MailContent,String Sender,String MailReceiver,String AuthorizationCode){
try {
//创建一个配置文件并保存
Properties properties = new Properties();
properties.setProperty("mail.host","smtp.qq.com");
properties.setProperty("mail.transport.protocol","smtp");
properties.setProperty("mail.smtp.auth","true");
//QQ存在一个特性设置SSL加密
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.ssl.socketFactory", sf);
//创建一个session对象
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Sender,AuthorizationCode);
//开启debug模式
session.setDebug(true);
//获取连接对象
Transport transport = session.getTransport();
//连接服务器
transport.connect("smtp.qq.com",Sender,AuthorizationCode);
//创建邮件对象
MimeMessage mimeMessage = new MimeMessage(session);
//邮件发送人
mimeMessage.setFrom(new InternetAddress(Sender));
//邮件接收人
mimeMessage.setRecipient(Message.RecipientType.TO,new InternetAddress(MailReceiver));
//邮件标题
mimeMessage.setSubject(MailTitle);
//邮件内容
mimeMessage.setContent(MailContent,"text/html;charset=UTF-8");
//发送邮件
transport.sendMessage(mimeMessage,mimeMessage.getAllRecipients());
//关闭连接
transport.close();
} catch (Exception e) {
System.out.println("邮件这里出错了");
邮件实现文本换行用"< br >"实现
package miaosu.utils;import com.sun.mail.util.MailSSLSocketFactory;import javax.mail.*;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import java.util.Properties;/** * Created by 马洋 on 2021/10/21 16:36 */public
首先搭建好springboot项目,引入pom文件
说明:若下面的包并非在新建demo引入的那么后续引入的时候注意选择版本,尽量不要选最新版,优先高引入量的版本,否则不兼容会提示包错误
<!--
邮件
发送-->
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail --
通过.Net FrameWork 2.0下提供的“System.Net.Mail”可以轻松的
实现
,本文列举了3种途径来发送:
1.通过Localhost;
2.通过普通
SMTP
;
3.通过SSL的
SMTP
;
这个控件好好用
第一,需要下载PHPMailer文件包phpmailer. http://phpmailer.sourceforge.net/
第二,确认你的服务器系统已经支持socket ,通过phpinfo();查看是否支持sockets(socket 是属于PHP扩展部分),如果显现为“enabled”,那就是支持了。
第三,把文件解压到你的web服务器目录下,调用类就可以了.
首先包含class.phpmailer.php,然后创建对象,设置参数,调用成员函数。具体请见下面的示例代码:
实例1,做成函数方便调用
require("phpmailer/class.phpmailer.php");
function
smtp
_mail( $sendto_email, $subject, $body, $extra_hdrs, $user_name){
$mail = new PHPMailer();
$mail->Is
SMTP
(); // send via
SMTP
$mail->Host = "200.162.244.66"; //
SMTP
servers
$mail->
SMTP
Auth = true; // turn on
SMTP
authentication
$mail->Username = "yourmail"; //
SMTP
username 注意:普通
邮件
认证不需要加 @域名
$mail->Password = "mailPassword"; //
SMTP
password
$mail->From = "yourmail@yourdomain.com"; // 发件人邮箱
$mail->FromName = "管理员"; // 发件人
$mail->CharSet = "GB2312"; // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"username"); // 收件人邮箱和姓名
$mail->AddReplyTo("yourmail@yourdomain.com","yourdomain.com");
//$mail->WordWrap = 50; // set word wrap
换行
字数
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
//
邮件
主题
$mail->Subject = $subject;
//
邮件
内容
$mail->Body = "
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
I love php。
</body>
</html>
$mail->AltBody ="text/html";
if(!$mail->Send())
echo "
邮件
发送有误 <p>";
echo "
邮件
错误信息: " . $mail->ErrorInfo;
exit;
else {
echo "$user_name
邮件
发送成功!<br />";
// 参数说明(发送到,
邮件
主题,
邮件
内容
, 附加信息, 用户名)
smtp
_mail("yourmail@yourdomain.com", "欢迎使用phpmailer!", "NULL", "yourdomain.com", "username");
在项目开发过程中,
发送邮件
时要在中文
内容
后面拼接一段英文
内容
,且中英文
内容
换行
显示。
刚开始在
java
代码中使用"\r\n"(“\n”--
换行
、“\r”--回车),代码调试时,字符串已经
换行
,但是邮箱接收展示之后,英文
内容
append中文
内容
之后。
后面想到,
邮件
查看时是静态html页面,其代表
换行
的是标签<br>,于是将"\r\n"换成"<br>",达到了
换行
要求。
过多基础概念我就不讲了, 直接翻书或者维基百科,
简单来说
SMTP
就是简单
邮件
传输协议, 既然是传输协议就是发
邮件
和收
邮件
, 两者都有.
和POP3和IMAP区别开来
从这里简单可以看出区别
其实就是收发
邮件
的双方都找了中间代理.
SMTP
是建立在TCP连接且端口为25的应用层协议. 主要是非实时的, 因为有的客户只会定期(15min)去询问代理邮箱有没有新的
邮件
这里就不进行文字赘述了, 等下实操代码用图片来分析流程
SMTP
命令和应答代码
应答代码, 服务器的返回消息
解决方案:
在创建Message对象的时候。
用setContent(Object o,String s);方法设置了
内容
格式
s,如果是text/html;charset=UTF-8
换行
符就是<br>.
转载于:https://www.cnblogs.com...
在 Vue 表格中
实现
换行
,可以使用 CSS 的 white-space 属性来控制文本的
换行
方式。具体步骤如下:
1. 在表格的单元格中使用 <pre> 标签或者设置 white-space 属性为 pre-wrap。
2. 将单元格的高度设置为足够高,以容纳多行文本。
3. 将单元格的 overflow 属性设置为 auto,以便在文本
内容
超过单元格高度时自动显示滚动条。
下面是一个示例代码:
```html
<template>
<table>
<td style="height: 50px; white-space: pre-wrap; overflow: auto;">
{{ content }}
</table>
</template>
<script>
export default {
data() {
return {
content:
'这是一段很长的文本,需要在表格中进行
换行
显示。这是一段很长的文本,需要在表格中进行
换行
显示。这是一段很长的文本,需要在表格中进行
换行
显示。',
</script>
上面的示例中,将单元格的 white-space 属性设置为 pre-wrap,可以让文本按照原始
格式
显示,同时自动
换行
。将单元格的 overflow 属性设置为 auto,可以在文本
内容
超过单元格高度时自动显示滚动条。通过设置单元格的高度,可以控制文本的行数。
点击idea打不开,报错说Error opening zip file or JAR manifest missing : C:\Users\Public\.jetbrains\jetbrains-a
zzq_0828:
获取本月月初日期,如:2022-01-11 00:00:00和月末
你渴望力量吗?:
一个类中快速回到顶部和底部
i迷ni:
一个类中快速回到顶部和底部
坏码农来福: