Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Last active December 13, 2021 17:37
Show Gist options
  • Save Kashif-E/58b00edc44d84aecd97e9ca97c3a7500 to your computer and use it in GitHub Desktop.
Save Kashif-E/58b00edc44d84aecd97e9ca97c3a7500 to your computer and use it in GitHub Desktop.
//Dependencies
// implementation 'com.sun.mail:android-mail:1.6.0'
// implementation'com.sun.mail:android-activation:1.6.0'
fun sendEmail(){
val prop = Properties().apply {
put("mail.smtp.auth", "true")
put("mail.smtp.starttls.enable","true")
put("mail.smtp.host","smtp.gmail.com")
put("mail.smtp.port","587")
}
Log.e("a","a")
val session = Session.getInstance(prop,object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication {
return PasswordAuthentication("email","pass")
}
})
Log.e("a","a")
try {
Log.e("a","a")
val message = MimeMessage(session).apply {
setFrom(InternetAddress("email"))
setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]"))
subject = "jhdjhaj"
setText("kjkdjakjdk")
}
Log.e("a","ass")
Transport.send(message)
}catch (e: MessagingException){
e.printStackTrace()
Log.e("a",e.message!!)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment