How to send emails in Swift using Mailgun

后端 未结 3 1323
野性不改
野性不改 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:41

    At this point I've answered my own question. The process isn't too terrible. Install mailgun using cocoapods. Link the objective-c code that is needed using an objective-c bridging header. Create an objective c file to house your method that will call the mailgun operation, and use it.

    #import 
    #import 
    
    @interface mailTest: NSObject
    - (void) sendMail: (NSString*)email;
    
    @end
    

    Then in my swift code I just call:

                var test: mailTest = mailTest()
                test.sendMail("testemail@testemail.com")
    

    Here is the mailTest header file. I created a .m file that implements the sendMail method and calls the code from the API and it works great. The only other thing that could be challenging is setting up the mailgun account and configuring your domain so that emails can be sent, but that isn't code related.

提交回复
热议问题