Send an email from my app without using MFMailComposeViewController

前端 未结 3 1929
孤独总比滥情好
孤独总比滥情好 2020-12-06 22:43

Is it possible to send an automatically generated email using my own email address to another email address of mine by clicking a button?

I tried to use MFMail

3条回答
  •  暖寄归人
    2020-12-06 23:12

    Yes there is a way using Swift-SMTP.

    Send email Create a Mail object and use your SMTP handle to send it. To set the sender and receiver of an email, use the User struct:

    let drLight = Mail.User(name: "Dr. Light", email: "drlight@gmail.com")
    let megaman = Mail.User(name: "Megaman", email: "megaman@gmail.com")
    
    let mail = Mail(
        from: drLight,
        to: [megaman],
        subject: "Humans and robots living together in harmony and equality.",
        text: "That was my ultimate wish."
    )
    
    smtp.send(mail) { (error) in
        if let error = error {
            print(error)
        }
    }
    

提交回复
热议问题