- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
更新:大家好,
我终于能够通过更改添加收件人的方式来解决这个问题。不知道为什么这与样板相反,但这让我克服了这个障碍。希望这对遇到类似问题的人有所帮助。
@Async
public void sendEmail(String to, String sendFrom, String subject, String content) {
log.debug("Send e-mail to '{}' with subject '{}' and content={}",
to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
mimeMessage.setRecipients(Message.RecipientType.TO, to);
mimeMessage.setContent(content, MediaType.TEXT_HTML_VALUE);
mimeMessage.setFrom(new InternetAddress(sendFrom));
mimeMessage.setSubject(subject);
javaMailSender.send(mimeMessage);
log.debug("Sent e-mail to '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to '{}', exception is: {}", to, e.getMessage());
}
}
原帖
经过几天的研究并接触了我认识的更多高级开发人员之后,我终于来到这里寻求帮助。非常感谢任何输入或帮助!
我正在使用 JHipster 堆栈提供的 MailService。
该应用程序正在使用我的个人电子邮件。它有两步验证,所以我不需要允许安全性较低的应用程序,因为我直接通过应用程序密码为我的应用程序提供密码。启用 IMAP 和 POP。
据我所知,我能够正确连接,只是无法发送给收件人。我在不同的域尝试了不同的电子邮件,但没有成功。如果我将应用程序密码更改为我的原始密码,它会提示说它必须使用特定于应用程序的密码。所以这让我确信我正在正确地进行身份验证/连接。
拉取源代码和调试将我带到 JavaMailSenderImpl 中的 doSend 并且错误是由 mimeMessage.getAllRecipients() 专门抛出的
我的控制台显示:
[DEBUG] com.myapp.aop.logging.LoggingAspect - Enter: com.myapp.service.MailService.sendEmail() with argument[s] = [myemail@gmail.com, myemail@gmail.com, hi, false, true]
[DEBUG] com.myapp.service.MailService - Send e-mail[multipart 'false' and html 'true'] to 'myemail@gmail.com' with subject 'subjecthi' and content=hi
[DEBUG] com.sun.mail.smtp - useEhlo true, useAuth true
[DEBUG] com.sun.mail.smtp - trying to connect to host "smtp.gmail.com", port 587, isSSL false
[DEBUG] com.sun.mail.smtp - connected to host "smtp.gmail.com", port: 587
[DEBUG] com.sun.mail.smtp - Found extension "SIZE", arg "35882577"
[DEBUG] com.sun.mail.smtp - Found extension "8BITMIME", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "STARTTLS", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "ENHANCEDSTATUSCODES", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "PIPELINING", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "CHUNKING", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "SMTPUTF8", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "SIZE", arg "35882577"
[DEBUG] com.sun.mail.smtp - Found extension "8BITMIME", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH"
[DEBUG] com.sun.mail.smtp - Found extension "ENHANCEDSTATUSCODES", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "PIPELINING", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "CHUNKING", arg ""
[DEBUG] com.sun.mail.smtp - Found extension "SMTPUTF8", arg ""
[DEBUG] com.sun.mail.smtp - Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
[WARN] com.myapp.service.MailService - E-mail could not be sent to user 'myemail@gmail.com', exception is: Failed messages: javax.mail.SendFailedException: No recipient addresses
[DEBUG] com.myapp.aop.logging.LoggingAspect - Exit: com.myapp.service.MailService.sendEmail() with result = null
我提供以下文件:
application.yml
# Disable the spring security default configuration from spring-boot-actuator
management.security.enabled: true
security.basic.enabled: false
# Disable Jolokia - An http/json bridge for remote JMX access
endpoints.jolokia.enabled: false
# security configuration (this key should be unique for your application, and kept secret)
jhipster.security.rememberme.key: securitykey
StripeSecretApiKey: mystripekey
async:
corePoolSize: 2
maxPoolSize: 50
queueCapacity: 10000
mail:
host: smtp.gmail.com
port: 587
username: myemail@gmail.com
password: myapppassword
protocol: smtp
tls: true
auth: true
from: mydomainemail@gmail.com
authentication:
oauth:
clientid: mydomainapp
secret: mysecret
# Token is valid 2 hours
tokenValidityInSeconds: 7200
swagger:
title: mydomain API
description: mydomain applications and beyond!
termsOfServiceUrl: http://jhipster.github.io/
contact:
license: Apache 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.html
OrderResource.java 调用邮件服务
mailService.sendEmail("myemail@gmail.com", "subject hi", "hi",false, true);
MailConfiguration.java
package com.myapp.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
@Configuration
public class MailConfiguration implements EnvironmentAware {
private static final String ENV_SPRING_MAIL = "mail.";
private static final String DEFAULT_HOST = "127.0.0.1";
private static final String PROP_HOST = "host";
private static final String DEFAULT_PROP_HOST = "localhost";
private static final String PROP_PORT = "port";
private static final String PROP_USER = "username";
private static final String PROP_PASSWORD = "password";
private static final String PROP_PROTO = "protocol";
private static final String PROP_TLS = "tls";
private static final String PROP_AUTH = "auth";
private static final String PROP_SMTP_AUTH = "mail.smtp.auth";
private static final String PROP_STARTTLS = "mail.smtp.starttls.enable";
private static final String PROP_TRANSPORT_PROTO = "mail.transport.protocol";
private final Logger log = LoggerFactory.getLogger(MailConfiguration.class);
private RelaxedPropertyResolver propertyResolver;
@Override
public void setEnvironment(Environment environment) {
this.propertyResolver = new RelaxedPropertyResolver(environment, ENV_SPRING_MAIL);
}
@Bean
public JavaMailSenderImpl javaMailSender() {
log.debug("Configuring mail server");
String host = propertyResolver.getProperty(PROP_HOST, DEFAULT_PROP_HOST);
int port = propertyResolver.getProperty(PROP_PORT, Integer.class, 0);
String user = propertyResolver.getProperty(PROP_USER);
String password = propertyResolver.getProperty(PROP_PASSWORD);
String protocol = propertyResolver.getProperty(PROP_PROTO);
Boolean tls = propertyResolver.getProperty(PROP_TLS, Boolean.class, false);
Boolean auth = propertyResolver.getProperty(PROP_AUTH, Boolean.class, false);
JavaMailSenderImpl sender = new JavaMailSenderImpl();
if (host != null && !host.isEmpty()) {
sender.setHost(host);
} else {
log.warn("Warning! Your SMTP server is not configured. We will try to use one on localhost.");
log.debug("Did you configure your SMTP settings in your application.yml?");
sender.setHost(DEFAULT_HOST);
}
sender.setPort(port);
sender.setUsername(user);
sender.setPassword(password);
Properties sendProperties = new Properties();
sendProperties.setProperty(PROP_SMTP_AUTH, auth.toString());
sendProperties.setProperty(PROP_STARTTLS, tls.toString());
sendProperties.setProperty(PROP_TRANSPORT_PROTO, protocol);
sender.setJavaMailProperties(sendProperties);
return sender;
}
}
邮件服务.java
package com.myapp.service;
import com.myapp.domain.User;
import org.apache.commons.lang.CharEncoding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.core.env.Environment;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.mail.Message;
import javax.mail.SendFailedException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Locale;
/**
* Service for sending e-mails.
* <p/>
* <p>
* We use the @Async annotation to send e-mails asynchronously.
* </p>
*/
@Service
public class MailService {
private final Logger log = LoggerFactory.getLogger(MailService.class);
@Inject
private Environment env;
@Inject
private JavaMailSenderImpl javaMailSender;
@Inject
private MessageSource messageSource;
@Inject
private SpringTemplateEngine templateEngine;
/**
* System default email address that sends the e-mails.
*/
private String from;
@PostConstruct
public void init() {
this.from = env.getProperty("mail.from");
}
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(message.getMimeMessage());
log.debug("Sent e-mail to User '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
}
}
@Async
public void sendPurchaseEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(message.getMimeMessage());
log.debug("Sent purchase e-mail to '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to '{}', exception is: {}", to, e.getMessage());
}
}
@Async
public void sendActivationEmail(User user, String baseUrl) {
log.debug("Sending activation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable("user", user);
context.setVariable("baseUrl", baseUrl);
String content = templateEngine.process("activationEmail", context);
String subject = messageSource.getMessage("email.activation.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
@Async
public void sendPurchaseNotificationEmail(String orderId, String email, String baseUrl) {
log.debug("Sending activation e-mail to '{}'", email);
Locale locale = Locale.forLanguageTag(Locale.ENGLISH.getLanguage());
String title = messageSource.getMessage("email.purchase.title", null, locale);
Context context = new Context(locale);
context.setVariable("orderId", orderId);
context.setVariable("baseUrl", baseUrl);
context.setVariable("subject", title);
context.setVariable("greeting", messageSource.getMessage("email.purchase.greeting", null, locale));
context.setVariable("text1", messageSource.getMessage("email.purchase.text1", null, locale));
context.setVariable("text2", messageSource.getMessage("email.purchase.text2", null, locale));
context.setVariable("signature", messageSource.getMessage("email.purchase.signature", null, locale));
String content = templateEngine.process("purchaseEmail", context);
sendPurchaseEmail(email, title, content, false, true);
}
}
最佳答案
另一个更新:今天我偶然发现了这篇文章,它启发我添加了一行 mimeMessage.saveChanges()
似乎解决了我之前的问题。感谢@dkar 的回答,他最终也为我解决了这个问题。在这里阅读他的回答:Original Answer
@Async
public void sendEmail(String to, String sendFrom, String subject, String content) {
log.debug("Send e-mail to '{}' with subject '{}' and content={}",
to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(sendFrom);
message.setSubject(subject);
message.setText(content, true);
mimeMessage.saveChanges();
javaMailSender.send(message.getMimeMessage());
log.debug("Sent e-mail to User '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
}
}
关于java - JHipster 邮件服务 - javax.mail.SendFailedException : No recipient addresses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31066065/
我一直在尝试在我的 MEAN 应用程序上设置和使用 nodemailer。这是 mail.js ...我用于我的 server.js 文件的路由。 'use strict'; const expres
我假设错误是我的后缀配置问题。我已按照说明中的步骤进行操作 here设置 apache/postfix/mailman。 用 mydomain.com 替换的真实域我创建了一个名为 mailman 的
升级到 Angular 2 Rc.5 后出现此错误。这是我的组件模板: 我的 app.module.ts 导入了 FormsModule 我还尝试在我的组件中声明 private recipien
我在 Google App Engine 上编写了一个应用程序,可以将电子邮件发送到一个地址。应用程序在测试期间达到了它的“通过电子邮件发送的收件人”配额限制。对于“已发送电子邮件的收件人”配额,是否
我有这个代码: 在我的表格(“电子邮件”)中,我有多个地址。(它们不是逗号分隔的。)我怎样才能将我的消息发送到所有这些地址? 最佳答案 while($row = mysql_fetch_array(
我几乎假设这是 JavaMail API 中的一个错误。 我正在执行 myMessage.reply(true) 来生成新消息。然而,尽管有传统的“回复所有人”理解,JavaMail 仍将我自己(第一
在 Symfony 文档中有这个条目: https://symfony.com/doc/current/mailer.html#email-addresses ...您可以将多个地址传递给每个方法:
这是我的第一个问题,所以我想保持简单。我对 Spring Framework 版本 4.1.8.RELEASE 中的 JavaMailSender 有问题。对于特定的 SMTP,它似乎不会将收件人添加
我正在尝试将电子邮件地址输入到撰写邮件窗口的收件人字段中。 我尝试获取收件人的地址属性,根据 VS,它应该给我电子邮件。 我收到的是一个看起来像这样的字符串: "/c=US/a=att/p=Micro
虽然有很多相同的问题,但没有一个解决方案对我有用。仅当有只有一个 收件人时才会发送邮件,否则会生成以下错误。此外,我只发送内部电子邮件,不发送外部电子邮件。 有什么想法吗? 代码: $to = 'on
注意:遗憾的是这不是 duplicate ,我已经尝试了那里提到的所有内容。 我试图用 Laravel/Swiftmailer 建立到我的邮件服务器的连接.我的 .env 的邮件部分如下所示: MAI
所以,当我尝试从我的网站使用 PHPmailer 发送邮件时,我刚刚收到此错误。 SMTP 错误:以下收件人失败:XXXX 我尝试设置 $mail->SMTPAuth = true;为 false 但
我正在使用 DocuSign 的 REST API 在嵌入式签名模式下创建信封。我在我的网站上对签名者进行身份验证,然后向 DocuSign 询问收件人 View 。用户可以签署文档,没关系。 我的问
所以我使用 Parse 来处理支持 Stripe 的应用程序。我们希望我们的用户能够兑现他们的应用积分,我们计划使用 Stripe 来处理这个问题。我已经能够在 Stripe 中成功创建客户,并将银行
我正在测试嵌入式签名,但遇到了以下错误: “您指定的收件人不是指定信封的有效收件人” 这适用于一个信封,但现在不适用于第二个。即使他们拥有完全相同的信息。 下面是 RequestStatus 的响应:
我有一个 Web 应用程序,它使用 SendGrid 的 X-SMTP 功能构建单个电子邮件,然后将其合并并转发到 X-SMTPAPI header 中指定的收件人列表。 此处的文档:http://s
在我们的应用程序中,发布者创建一条消息并将其发送到一个主题。 然后它需要等待,当所有主题的订阅者都确认消息时。 它不会出现,消息总线实现可以自动执行此操作。因此,我们倾向于让每个订阅者在完成后向客户发
我正在尝试根据本文档在 Win 7 机器上创建一个基本的 akka 集群: http://doc.akka.io/docs/akka/snapshot/scala/cluster-usage.html
我正在使用codeigniter。我测试过将电子邮件发送到错误的不存在的地址,例如t@t.com。 我的代码只是控制者的一种方法,例如: function test() { $this->em
有人可以告诉我如何向此代码添加“抄送收件人”吗? “致收件人”和代码均按预期工作。感谢您抽出时间。 Sub ForwardEmail(item As Outlook.MailItem) ' Dim o
我是一名优秀的程序员,十分优秀!