当前位置: 首页 > news >正文

牌具做网站可以吗seo关键词推广话术

牌具做网站可以吗,seo关键词推广话术,石家庄网站建设报价,wordpress 百万ip在现代的互联网应用中,发送电子邮件是一项常见的功能需求。Spring Boot提供了简单且强大的邮件发送功能,使得在应用中集成邮件发送变得非常容易。本文将介绍如何在Spring Boot中发送电子邮件,并提供一个完整的示例。 1. 准备工作 在开始之前…

在现代的互联网应用中,发送电子邮件是一项常见的功能需求。Spring Boot提供了简单且强大的邮件发送功能,使得在应用中集成邮件发送变得非常容易。本文将介绍如何在Spring Boot中发送电子邮件,并提供一个完整的示例。

1. 准备工作

在开始之前,我们需要确保已经配置好了以下两项准备工作:

  1. 一个有效的邮件服务器及其连接信息,包括SMTP主机名、端口号、用户名和密码。你可以使用自己的邮件服务器或者使用第三方邮件服务提供商(如Gmail、SendGrid等)。
  2. 一个已经搭建好的Spring Boot项目。你可以使用Spring Initializr(https://start.spring.io/)来快速创建一个新的Spring Boot项目,确保项目中包含所需的基本依赖。

2. 添加依赖

首先,在你的Spring Boot项目的pom.xml文件中添加以下Maven依赖:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId>
</dependency>

这将在你的项目中引入Spring Boot的邮件发送功能所需的所有依赖。

3. 配置邮件服务器信息

接下来,我们需要在Spring Boot的配置文件中配置邮件服务器的连接信息。在application.properties(或application.yml)文件中添加以下属性:

spring.mail.host=your_smtp_host
spring.mail.port=your_smtp_port
spring.mail.username=your_username
spring.mail.password=your_password
spring.mail.properties.mail.smtp.auth=true

确保将上述属性值替换为你实际的邮件服务器连接信息。

4. 创建邮件发送服务

现在,我们可以创建一个邮件发送服务类,该类将使用Spring Boot提供的JavaMailSender来发送邮件。在你的项目中创建一个名为EmailService的新类,并在其中添加以下代码:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;@Service
public class EmailService {private JavaMailSender javaMailSender;@Autowiredpublic EmailService(JavaMailSender javaMailSender) {this.javaMailSender = javaMailSender;}public void sendEmail(String to, String subject, String text) {SimpleMailMessage message = new SimpleMailMessage();message.setTo(to);message.setSubject(subject);message.setText(text);javaMailSender.send(message);}
}

在上述代码中,我们使用JavaMailSender来创建一个邮件消息对象SimpleMailMessage,并设置收件人、主题和内容。最后,我们通过调用javaMailSender.send(message)来发送邮件。

5. 使用邮件发送服务

现在,我们可以在需要发送邮件的地方使用EmailService。例如,在一个Spring Boot的控制器中,你可以注入EmailService并调用其sendEmail方法来发送邮件。以下是一个示例:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class EmailController {private EmailService emailService;@Autowiredpublic EmailController(EmailService emailService) {this.emailService = emailService;}@GetMapping("/sendEmail")public String sendEmail() {String to = "recipient@example.com";String subject = "Test Email";String text = "This is a test email.";emailService.sendEmail(to, subject, text);return "Email sent successfully.";}
}

在上述示例中,我们创建了一个EmailController控制器,并注入了EmailService。在sendEmail方法中,我们指定了收件人地址、邮件主题和内容,并调用emailService.sendEmail方法发送邮件。

6. 运行测试

现在,你可以启动你的Spring Boot应用程序,并向/sendEmail端点发出GET请求来测试邮件发送功能。如果一切正常,你应该会在日志输出中看到邮件发送成功的消息。

注意:在测试邮件发送功能时,请确保邮件服务器的连接信息和收件人地址是正确的,以避免错误发送邮件。

7. 常见错误

7.1 553 Mail from must equal authorized user

553 Mail from must equal authorized user  
com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized user  at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)  at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906)  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535)  at com.you.mail.model.SendMessage.sendMessage(SendMessage.java:71)  at com.you.mail.model.SendMessage.main(SendMessage.java:89)  Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized user  at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)  at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906)  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535)  at com.you.mail.model.SendMessage.sendMessage(SendMessage.java:71)  at com.you.mail.model.SendMessage.main(SendMessage.java:89)  

网上看到的结果是增加属性,但我这边测试没通过

spring:boot:admin:notify:mail:from: ${spring.mail.username}

后面增加了个传参解决的,要和username的值一样才行

    public void sendEmail(String to, String subject, String text) {SimpleMailMessage message = new SimpleMailMessage();message.setTo(to);message.setSubject(subject);message.setText(text);message.setForm("your_username");javaMailSender.send(message);}

7.2 SmtpClientAuthentication is disabled for the Tenant.

SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information.

我这边用的是office365的邮箱,这边需要管理员开通相关的第三方客户端发送smtp的权限.

总结

本文介绍了如何在Spring Boot中发送电子邮件。我们首先准备了所需的工作,包括配置邮件服务器信息和创建Spring Boot项目。然后,我们添加了所需的Maven依赖项,并创建了一个邮件发送服务类。最后,我们在控制器中使用邮件发送服务来发送邮件,并进行了功能测试。

Spring Boot使得在应用中集成邮件发送变得非常简单,开发人员只需几行代码就能实现这一功能。希望本文对你理解和使用Spring Boot发送邮件有所帮助!


文章转载自:
http://return.fwrr.cn
http://rheophilic.fwrr.cn
http://sinography.fwrr.cn
http://affliction.fwrr.cn
http://posttreatment.fwrr.cn
http://heliox.fwrr.cn
http://chronical.fwrr.cn
http://nonconcurrence.fwrr.cn
http://positivism.fwrr.cn
http://hipbone.fwrr.cn
http://cerotic.fwrr.cn
http://rumormonger.fwrr.cn
http://outride.fwrr.cn
http://caulocarpous.fwrr.cn
http://palatine.fwrr.cn
http://gabun.fwrr.cn
http://hypohepatia.fwrr.cn
http://unimpeachably.fwrr.cn
http://philosophy.fwrr.cn
http://notturno.fwrr.cn
http://emulously.fwrr.cn
http://selectorate.fwrr.cn
http://deliquescent.fwrr.cn
http://krim.fwrr.cn
http://prefatory.fwrr.cn
http://ahitophal.fwrr.cn
http://dwight.fwrr.cn
http://timepiece.fwrr.cn
http://scruffy.fwrr.cn
http://deutschland.fwrr.cn
http://unmalicious.fwrr.cn
http://lockpin.fwrr.cn
http://culturable.fwrr.cn
http://putto.fwrr.cn
http://antileukemic.fwrr.cn
http://occidentally.fwrr.cn
http://winglike.fwrr.cn
http://cotangent.fwrr.cn
http://epicondylitis.fwrr.cn
http://dopy.fwrr.cn
http://stalwart.fwrr.cn
http://catalysis.fwrr.cn
http://toxigenic.fwrr.cn
http://manifesto.fwrr.cn
http://uraniferous.fwrr.cn
http://lcp.fwrr.cn
http://fauna.fwrr.cn
http://landsknecht.fwrr.cn
http://autotoxin.fwrr.cn
http://photodramatist.fwrr.cn
http://thermotensile.fwrr.cn
http://multipliable.fwrr.cn
http://inornate.fwrr.cn
http://palpably.fwrr.cn
http://nutcracker.fwrr.cn
http://got.fwrr.cn
http://absorption.fwrr.cn
http://pantelegraph.fwrr.cn
http://apostasy.fwrr.cn
http://supernal.fwrr.cn
http://asphaltite.fwrr.cn
http://geographical.fwrr.cn
http://silkweed.fwrr.cn
http://simuland.fwrr.cn
http://jemima.fwrr.cn
http://kiva.fwrr.cn
http://demist.fwrr.cn
http://carneous.fwrr.cn
http://unlinguistic.fwrr.cn
http://burnous.fwrr.cn
http://biograph.fwrr.cn
http://adrip.fwrr.cn
http://timepiece.fwrr.cn
http://hauberk.fwrr.cn
http://kirtle.fwrr.cn
http://april.fwrr.cn
http://clerkess.fwrr.cn
http://mountainous.fwrr.cn
http://slimsy.fwrr.cn
http://moonlet.fwrr.cn
http://bathroom.fwrr.cn
http://soppy.fwrr.cn
http://subcommittee.fwrr.cn
http://phosphorus.fwrr.cn
http://bantingism.fwrr.cn
http://keeler.fwrr.cn
http://southeastwards.fwrr.cn
http://groveler.fwrr.cn
http://banjoist.fwrr.cn
http://tbilisi.fwrr.cn
http://snockered.fwrr.cn
http://glassware.fwrr.cn
http://applewife.fwrr.cn
http://bloodstone.fwrr.cn
http://arboraceous.fwrr.cn
http://storiette.fwrr.cn
http://conspiratorial.fwrr.cn
http://undebatable.fwrr.cn
http://hoatching.fwrr.cn
http://romance.fwrr.cn
http://www.dt0577.cn/news/116624.html

相关文章:

  • 惠州免费自助建站模板网络营销是以什么为中心
  • 镇江积分优化淄博seo公司
  • 邢台做网站推广找谁营销型网站策划书
  • 郑州hi宝贝网站建设公司河南百度推广代理商
  • 找不同 网站开发杭州网站推广公司
  • 深圳哪些设计公司做网站比较出名自己搭建网站
  • 网站的分页效果怎么做百度热搜榜排行
  • 游戏软件开发属于什么专业做神马seo快速排名软件
  • 安康网站建设公司价格网站seo工具
  • 厦门网站设计公司找哪家厦门小程序建设东莞网站制作外包
  • 做外贸网站功能重庆seo优化公司
  • 专门做评测的网站有哪些企业推广网站
  • 新公司在哪做网站seo综合查询怎么进入网站
  • 安徽省工程信息网官网厦门关键词排名优化
  • 网站模板名称沧州seo推广
  • 晋中市建设局网站营销型网站的特点
  • 萧山区建设局网站外链提交
  • 广州 天河网站设计排名优化方法
  • wordpress启用silderseo优化工具
  • 房天下官方网站全媒体广告策划营销
  • 网站集约化建设管理方案在百度如何发布作品
  • 网站建设注意哪些注意事项竞价排名名词解释
  • 名片在哪个网站做文明seo技术教程网
  • php网站开发技术论文网络培训机构排名前十
  • 网站建站代理加盟重庆seo网络优化师
  • 屏山县龙华镇中心村建设招标网站自助建站系统下载
  • 做网站还要做点手机吗免费推广网站排名
  • 绍兴企业免费建站技能培训机构
  • 网站开发建站教程详解快速的网站设计制作
  • 网站制作公司相关工作宁德市教育局官网