401 Forbidden when sending email with Swift and Mailgun

后端 未结 2 964
慢半拍i
慢半拍i 2021-01-20 03:40

I have the following code but consistently get error 401 forbidden when attempting to run it:

func email() {
    let session = URLSession.shared
    let requ         


        
2条回答
  •  北海茫月
    2021-01-20 03:56

    You need to set the uesrname and the password.

    Something like this:

    request.setValue("Basic \(base64Credentials)", forHTTPHeaderField: "Authorization")
    

    and base64Credentials is the :

    let credentials= String(format: "%@:%@", username, password)
    let base64Credentials= credentials.data(using: String.Encoding.utf8)!
    

提交回复
热议问题