mirror of https://github.com/bvn13/covid19-ru.git
fixed mail delivery
parent
a3482987ed
commit
2da55bd99a
|
@ -16,38 +16,55 @@ limitations under the License.
|
|||
|
||||
package com.bvn13.covid19.scheduler.updater.stopcoronovirusrf;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@Slf4j
|
||||
@ConfigurationProperties(prefix = "app.mail")
|
||||
public class MailConfig {
|
||||
|
||||
@NotBlank
|
||||
private String username;
|
||||
@NotBlank
|
||||
private String password;
|
||||
@NotBlank
|
||||
private String host;
|
||||
@Min(1)
|
||||
@Max(65536)
|
||||
private int port;
|
||||
@NotBlank
|
||||
private String sender;
|
||||
@NotBlank
|
||||
private String recipient;
|
||||
@NotBlank
|
||||
private String subject;
|
||||
private boolean debugMode;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
if (StringUtils.isBlank(host) ||
|
||||
StringUtils.isBlank(username) ||
|
||||
StringUtils.isBlank(password) ||
|
||||
StringUtils.isBlank(sender) ||
|
||||
StringUtils.isBlank(recipient) ||
|
||||
StringUtils.isBlank(subject) ||
|
||||
port <= 0 || port > 65536) {
|
||||
throw new IllegalArgumentException("Mail endpoint has no arguments: " + constructEndpoint());
|
||||
}
|
||||
|
||||
log.info("MAIL ENDPOINT: " + constructEndpoint());
|
||||
}
|
||||
|
||||
public String constructEndpoint() {
|
||||
return "smtp://" + host + ":" + port +
|
||||
return "smtps://" + host + ":" + port +
|
||||
"?username=" + username +
|
||||
"&password=" + password +
|
||||
"&from=" + sender +
|
||||
"&to=" + recipient +
|
||||
"&subject=" + subject;
|
||||
"&subject=" + subject +
|
||||
"&debugMode=" + (debugMode ? "true" : "false");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ app:
|
|||
password: <mail-password>
|
||||
host: smtp.yandex.ru
|
||||
port: 465
|
||||
to: <your-password>
|
||||
sender: <your-sender>
|
||||
recipient: <your-recipient>
|
||||
subject: Ошибка загрузки данных COVID19
|
||||
debugMode: false
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
Loading…
Reference in New Issue