14 Aralık 2018 Cuma

SpringMail application.properties Ayarları

Giriş
Genellikle şu alanları mutlaka doldurmak gerekiyor
- spring.mail.host
- spring.mail.port
- spring.mail.username
- spring.mail.password

Daha sonra gerekli olabilecek alanları dolduruyoruz. Mesela : 
- spring.mail.properties.mail.smtp.auth
- spring.mail.properties.mail.smtp.starttls.enable

Örnek
Şöyle yaparız.
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=*******
spring.mail.password= *******

#mail properties
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true

-Dhttp.proxyHost=192.168.15.1
-Dhttp.proxyPort=2120 
-Dhttps.proxyHost=192.168.15.1
-Dhttps.proxyPort=2120
-Dhttps.proxySet=true 
-Dhttp.proxySet=true

server.use-forwarded-headers=true
Örnek
Aslında aynı şey yaml ile yapılıyor. Şöyle yaparız.
spring:  
  mail:
    host: smtp.gmail.com
    port: 587
    username: xxxxxxxx@gmail.com
    password: xxxxxx
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
Örnek - tls
Şöyle yaparız.
spring.mail.host=mail.nomadlogicapp.com
spring.mail.username=noreply@nomadlogicapp.com
spring.mail.password=TXKi6zj2
spring.mail.properties.mail.smtp.port=587
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
Örnek - test connection
Açıklaması şöyle
The property spring.mail.test-connection when set to true, test the SMTP connection on application launch, which means if the connection fails, an error will be thrown, and the application launch will fail.
Şöyle yaparız
spring.mail.host=smtp.mailgun.org
spring.mail.port=587
spring.mail.username=<mailgun_username>
spring.mail.password=<mailgun_password>
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.from=contact@tericcabrel.com
spring.mail.default-encoding=UTF-8
spring.mail.test-connection=false
Örnek - timeout
Şöyle yaparız. Burada bağlantı ve yazma işlemleri için zaman aşımı belirtiliyor.
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=xxx@gmail.com
spring.mail.password=pw

# Other properties
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000

# TLS , port 587
spring.mail.properties.mail.smtp.starttls.enable=true

Hiç yorum yok:

Yorum Gönder