MailSender基於JavaMail for Android開發,旨在幫助開發者在Android平臺快速實現郵件發送html
repositories {
jcenter()
}
implementation 'com.teprinciple:mailsender:1.1.0'
複製代碼
// 建立郵箱
val mail = Mail().apply {
mailServerHost = "smtp.qq.com"
mailServerPort = "587"
fromAddress = "xxxxxxxx@foxmail.com"
password = "xxxxxxxx"
toAddress = arrayListOf("xxxxxxxx@qq.com")
subject = "MailSender"
content = "MailSender Android快速實現發送郵件"
attachFiles = arrayListOf(file)
}
// 發送郵箱
MailSender.getInstance().sendMail(mail)
複製代碼
// 建立郵箱
Mail mail = new Mail();
mail.mailServerHost = "smtp.qq.com";
mail.mailServerPort = "587";
mail.fromAddress = "xxxxxxxx@foxmail.com";
mail.password = "xxxxxxxx";
mail.toAddress = arrayListOf("xxxxxxxx@qq.com");
mail.subject = "MailSender";
mail.content = "MailSender Android快速實現發送郵件";
mail.attachFiles = arrayListOf(file);
// 發送郵箱
MailSender.getInstance().sendMail(mail);
複製代碼
只需將Mail類中的content,換成html或者SpannableStringjava
// html 內容的郵件
content =
""" <p1 style = "color: red">MailSender</p1><br/> <p1 style = "color: blue">Android快速實現發送郵件</p1><br/> <p1 style = "color: blue">https://github.com/teprinciple/MailSender</p1><br/> <p6 style = "color: gray">這是html內容的郵件</p1><br/> <img src="https://avatars2.githubusercontent.com/u/19629464?s=460&v=4"> """
//SpannableString內容的郵件
content = SpanUtils(this@MainActivity)
.appendLine("MailSender").setFontSize(28, true).setForegroundColor(Color.RED)
.appendLine("Android快速實現發送郵件")
.appendLine("https://github.com/teprinciple/MailSender").setForegroundColor(Color.BLUE)
.appendLine("這是SpannableString內容的郵件").setForegroundColor(Color.parseColor("#efefef")).setFontSize(12, true)
.create()
複製代碼
屬性 | 說明 | 是否必須 |
---|---|---|
mailServerHost | 發件郵箱服務器 | true |
mailServerPort | 發件郵箱服務器端口 | true |
fromAddress | 發件郵箱地址 | true |
password | 發件箱受權碼(密碼) | true |
toAddress | 直接收件人郵箱 | true |
ccAddress | 抄送者郵箱 | false |
bccAddress | 密送者郵箱 | false |
subject | 郵件主題 | false |
content | 郵件內容 | false |
attachFiles | 附件 | false |
下面是qq郵箱受權碼獲取 怎樣獲取受權碼?git