How to send emails in Swift using Mailgun

后端 未结 3 1294
野性不改
野性不改 2021-01-01 02:55

I have the need to send automatic emails in a Swift project I\'m working on. So far my best lead seems to be using Mailgun. (I\'m open to better options if anyone has liked

3条回答
  •  别那么骄傲
    2021-01-01 03:49

    There's another option that you could try if you wanted as much as possible to be on the Swift side:

    1. If you don't have a bridging header yet, create a dummy objective-c file (add new file to project). Xcode will ask if you will like to add a header file (this will sort out the header for you automatically)

    2. Add this to your bridging header (providing you already imported mail gun using cocoa pods): #import "mailgun/Mailgun.h"

    3. Import maligun in your swift class: import mailgun

    4. Simply use mailgun's API in swift as you would in Objective-C:

      @IBAction func sendEmail(_ sender: Any) {
      
          let mailgun = Mailgun.client(withDomain: "samples.mailgun.org", apiKey: "key-3ax6xnjp29jd6fds4gc373sgvjxteol0")
      
          mailgun?.sendMessage(to: "Jay Baird ", from: "Excited User ", subject: "Mailgun is awesome!", body: "A unicode snowman for you! ☃")
      
      }
      

提交回复
热议问题