spring裡發郵件到郵箱的實現

2021-09-29 10:43:58 字數 1504 閱讀 9414

注意,使用的是qq郵箱,qq郵箱-設定-賬戶裡的協議要開啟!

# 郵件 smtp 設定

spring.mail.username=你的郵箱

# 如果用 qq 郵箱, 就用下面的 host

spring.mail.host=smtp.qq.com

spring.mail.password=你的密碼

spring.mail.port=465

spring.mail.protocol=smtps

非同步、同步實現

package kybmig.ssm.controller;

import kybmig.ssm.utility;

import org.springframework.boot.autoconfigure.mail.mailproperties;

import org.springframework.mail.mailsender;

import org.springframework.mail.******mailmessage;

import org.springframework.scheduling.annotation.async;

import org.springframework.stereotype.component;

import org.springframework.stereotype.controller;

import org.springframework.web.bind.annotation.responsebody;

import org.springframework.web.servlet.modelandview;

@component

class asyncmail

@async

public void sendmail(string address, string title, string content)

}@component

class syncmail

public void sendmail(string address, string title, string content)

}@controller

public class mailcontroller

public modelandview index()

@responsebody

public string send(string address, string title, string content) else

}@responsebody

public string asysend(string address, string title, string content) else

}}

加非同步註解@enableasync

@enableasync

public static void main(string args) }

beego發郵件服務 郵箱

將使用者的資訊,儲存到資料庫中以後,接下來可以給使用者傳送一封郵件,並且告訴使用者只有去郵箱中啟用以後,才能進行登入。給使用者傳送郵件乙個很重要的好處就是,可以判斷使用者在註冊時輸入的郵箱是否正確。第一 指定傳送郵件的配置資訊。config 這裡指定了發件人的郵箱名稱,對應的傳送密碼,對應smtp伺...

python發郵件(163郵箱)

import smtplib from email.mime.text import mimetext from email.header import header class sendemail def init self,sender smtpserver smtp.163.com usern...

實現郵箱發郵件的功能

實現流程 1.登入郵件伺服器 mailutils.createsession 伺服器位址 登入名 密碼 2.建立郵件物件 發件人 收件人 主題 正文 3.傳送 需要第一步得到session,和第二步的郵件物件 例項原始碼 test public void fun throws messagingex...