使用spring的JavaMailSenderImpl
JavaMailSenderImpl jmsi = new JavaMailSenderImpl();
// 这个host相关的邮箱都会介绍
jmsi.setHost("smtp.sina.com");
jmsi.setPort(25);
// 或者test@sina.com,注册的邮箱的用户名和密码
jmsi.setUsername("test");
jmsi.setPassword("test");
Properties p = new Properties();
// 邮件认证
p.setProperty("mail.smtp.auth", "true");
jmsi.setJavaMailProperties(p);
MimeMessage mimeMessage = jmsi.createMimeMessage();
// 编码UTF-8
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
// 邮箱名必须是已注册的,后面可以添加一个展示名,不添加默认为邮箱名
helper.setFrom("test@sina.com","用户找回密码");
helper.setTo("test@yahoo.com.cn");
helper.setSubject("用户找回密码");
helper.setText("邮箱找回密码哦!",true);
jmsi.send(mimeMessage);
javaMail发邮件
Properties p = new Properties();
p.setProperty("mail.smtp.auth", "true");
Transport transport;
Session session = Session.getInstance(p);
transport = session.getTransport("smtp");
transport.connect("smtp.sina.com", 25, "test_report", "test_report");
MimeMessage mm = new MimeMessage(session);
mm.setSentDate(new Date());
mm.saveChanges();
mm.setText("邮箱找回密码哦!!!!!!!!!!!!!!!", "UTF-8");
mm.setSubject("用户找回密码", "UTF-8");
mm.setFrom(new InternetAddress("test_report@sina.com", "【注册】"));
mm.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("test@yahoo.com.cn"));
Address[] addresses = mm.getRecipients(MimeMessage.RecipientType.TO);
transport.sendMessage(mm, addresses);
分享到:
相关推荐
其中,Spring的JavaMailSenderImpl是用于发送电子邮件的一个重要工具,它使得开发者能够方便地集成邮件服务到他们的应用中。下面将详细介绍这个知识点。 **1. Spring的JavaMailSender接口与JavaMailSenderImpl实现*...
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailProperties.getHost()); mailSender.setPort(mailProperties.getPort()); mailSender.setUsername(mailProperties....
return new JavaMailSenderImpl() { @Override public void configure(MailSenderConfigurationBuilder builder) { builder.properties() .host(host) .port(port) .protocol("smtp") .username(username) ...
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(smtpHost); mailSender.setPort(smtpPort); mailSender.setUsername(username); mailSender.setPassword(password); ...
JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost("smtp.gmail.com"); sender.setPort(465); Properties props = sender.getJavaMailProperties(); props.put("mail.smtp.auth", "true"); ...
Spring JavaMailSenderImpl does not show proper message when recipient list is empty [SPR-17540] #22072 Potential resource leak in DataSourceUtils.doGetConnection [SPR-17559] #22091 SpEL, error parsing...
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="username" value="your-email@example.com"/> <property name="password" value="your-password...
它包含了`JavaMailSender`接口和`JavaMailSenderImpl`实现,这是Spring使用JavaMail API发送邮件的基础。 3. **java-mail**: JavaMail API是一个用于处理邮件的开源库,包括SMTP、POP3、IMAP等协议。在Spring中,...
在Spring Boot应用中,我们可以利用Spring Framework的JavaMailSender接口以及其实现类JavaMailSenderImpl来构建电子邮件发送功能。首先,我们需要在项目中引入相关的依赖。在`pom.xml`或`build.gradle`文件中添加`...
Spring Email抽象核心接口MailSender,其实现类JavaMailSenderImpl,在其中配置邮件 服务器host,pssword,协议等 。。。。。 1.发送简单的消息 SimpleMailMessage:发送简单的消息 2.发送丰富的消息(比如带有附件,内...
在Spring Boot应用中,利用JavaMailSender发送邮件是一种常见的需求,Spring Boot的`spring-boot-starter-mail`模块为我们提供了方便的自动化配置。首先,我们需要在项目的`pom.xml`文件中引入这个依赖: ```xml ...
Spring内部提供了一个邮件发送器`JavaMailSenderImpl`,它实现了`JavaMailSender`接口。通过这个组件,开发者可以方便地发送文本邮件、HTML邮件以及带附件的邮件。`JavaMailSenderImpl`作为一个普通的Java Bean,...
在本篇博文中,我们将深入探讨如何使用Spring Boot发送电子邮件,这是Spring Boot框架的一个非常实用的功能,可以帮助开发者轻松实现企业级应用中的邮件服务。通过学习本文,你可以掌握Spring Boot集成...
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="smtp.example.com" /> <!-- 替换为实际SMTP服务器地址 --> ...
return new JavaMailSenderImpl() { @Override public Session getSession() { return session; } }; } } ``` 现在我们有了发送邮件的基础设置,可以编写服务类`MailService`来处理各种邮件类型: ```java ...
return new JavaMailSenderImpl() { @Override public Session getSession() { return session; } @Override public void send(MimeMessagePreparator preparator) throws MailException { // 自定义邮件...
Spring JavaMailSenderImpl does not show proper message when recipient list is empty [SPR-17540] #22072 'default-lazy-init' attribute is not processed when XSD validation is disabled [SPR-8335] #12983
Spring框架JavaMailSender发送邮件工具类是基于JavaMail API实现的,它使用JavaMailSenderImpl类来发送邮件。JavaMailSenderImpl类实现了MailSender和JavaMailSender接口,提供了邮件发送的基本功能。通过设置邮件...
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="username" value="your-email@gmail.com"/> <property name="password" value="your-password"/>...
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(host); mailSender.setPort(port); mailSender.setUsername(username); mailSender.setPassword(password); Properties ...