我正在使用Swift通过MailCore2发送电子邮件,但遇到一个小问题。我创建了一个注册应用程序,当用户单击“提交”按钮时,他/她的所有数据都使用MailCore2发送到电子邮件地址。大多数电子邮件已发送,但在某些电子邮件之间没有发送。数据存储在数据库中,但不发送电子邮件。有时发送电子邮件,而其他时候不发送电子邮件。
我尝试过更新Podfile中的MailCore2 Pod。我试图找到其他电子邮件客户端,但找不到任何有效的电子邮件客户端。请分享其他可以与Swift一起使用的电子邮件客户端。我共享的代码与Mailcore2一起使用。有时,电子邮件已发送,而其他时间则不发送。
@IBAction func submitButton(_ sender: Any) {
\\ Please ask if you want the database code also. I've omitted it from this function so as to avoid unnecessary confusion.
let smtpSession = MCOSMTPSession()
smtpSession.hostname = "smtp.gmail.com"
smtpSession.username = "xxx@gmail.com"
smtpSession.password = "xxxxxxxx"
smtpSession.port = 465
smtpSession.authType = MCOAuthType.saslPlain
smtpSession.connectionType = MCOConnectionType.TLS
smtpSession.connectionLogger = {(connectionID, type, data) in
if data != nil {
if let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){
NSLog("Connectionlogger: \(string)")
}
}
}
let builder = MCOMessageBuilder()
builder.header.to = [MCOAddress(displayName: "Director", mailbox: "xxxxxxx@gmail.com")]
builder.header.bcc = [MCOAddress(displayName: "xxxxxxxx", mailbox: "xxxxxx@gmail.com")]
builder.header.from = MCOAddress(displayName: "xxxxxx", mailbox: "xxxxxx@gmail.com")
builder.header.subject = "New Inquiry"
builder.textBody = "Hi xxxx, \nNew Inquiry at \(today!). Here are his/her details. This info has reached your career counsellor too. Have a great day! \n\nName: \(name.text!) \nEmail Address: \(email.text!) \nPhone Number: \(phoneNumber.text!) \nHome Address: \(homeAddress.text!) \nCall: \(callStatus) \nWhatsapp: \(whatsappStatus) \nEmail: \(emailStatus) \nSMS: \(smsStatus) \nInquiry Number: \(self.inquiryNumber.text!) \nEducational Qualification: \(educationalqualification.text!) \n\The xxxxxxxxx App"
let rfc822Data = builder.data()
let sendOperation = smtpSession.sendOperation(with: rfc822Data)
sendOperation?.start { (error) -> Void in
if (error != nil) {
NSLog("Error sending email: \(error)")
} else {
NSLog("Successfully sent email!")
}
}
}
我希望每次单击“提交”按钮时都会发送电子邮件。