Bir uygulamada hızlıca e-posta gönderirsiniz. Örneğin, kullanıcınızın Parse (veya değil) ile bir sosyal medya uygulamasında parolalarını sıfırlamasını istemek gibi, ancak otomatik olmasını istediğiniz için MessageUI kullanmıyorsunuz. Bazı araştırmalar yaptım ve posta tenekesi ile mümkün olabileceğini öğrendim ama hızlı ve XCode 6 ile nasıl kullanılacağını anlayamıyorum. Lütfen bana yardım edebilir misiniz?Swift ile e-posta gönderme
cevap
Elbette yapabilirsin.
import Foundation
import UIKit
import MessageUI
class ViewController: ViewController,MFMailComposeViewControllerDelegate {
@IBAction func sendEmailButtonTapped(sender: AnyObject) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["[email protected]"])
mailComposerVC.setSubject("Sending you an in-app e-mail...")
mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
Kaynak Andrew Bancroft
sorudan: "ama IOS9.2 simulatörü kullanırken otomatik olarak" –
otomatik olmasını istiyorsanız MessageUI kullanmıyorsunuz, görünüm "viewServiceDidTerminateWithError" mesajıyla kilitleniyor. Ancak diğer sorular bunun sadece simülatörle ilgili problem olduğunu ve çözümün gerçek cihazlarda çalışacağını belirtir. – Dashrath
Looks _very_ tanıdık https://www.andrewcbancroft.com/2014/08/25/send-email-in-app-using-mfmailcomposeviewcontroller- with-swift/ – n13
Ayrıştırma kutudan çıktığı Mailgun ve Mandrill destekler. Bkz. documentation
Bir CloudCode işlevi yazmanız, ardından uygulamanızdan çağırmanız gerekir.
PFCloud.callFunctionInBackground("hello", withParameters:[:]) {
(result: AnyObject!, error: NSError!) -> Void in
if error == nil {
// result is "Hello world!"
}
}
Mailgun kullanarak posta göndermek için örnek kod parçacıkları.
var Mailgun = require('mailgun');
Mailgun.initialize('myDomainName', 'myAPIKey');
Mailgun.sendEmail({
to: "[email protected]",
from: "[email protected]",
subject: "Hello from Cloud Code!",
text: "Using Parse and Mailgun is great!"
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
İçe aktarmam gereken bir modül var mı? Bana hata veriyor –
var Mailgun = required ('mailgun'); – picciano
Ben de aynı kodu var ve hala hataları alıyorum da hızlı bir şekilde " –
- 1. Mac Terminal Eklentiyle Eposta Gönderme
- 2. Eposta çiftleşmiş
- 3. eposta hyperlinkbutton
- 4. PHP eposta doğrulama
- 5. SES Eposta değil ben laravel
- 6. Eposta biçimlendirme tableView
- 7. Eposta soğukkanlılık iOS 8
- 8. Eposta açık bildirimi - raylar
- 9. Swift kullanarak bir HTML e-postası gönderme
- 10. springMVC + thymleaf kullanım templateResolver eposta
- 11. Swift 2.3 ile derlenen modül Swift 3.0
- 12. Parse.com Swift ile arama özelliği Swift
- 13. SendKeys ile 'i' harfi gönderme
- 14. Mekanizma ile Form Gönderme (Python)
- 15. Teslimat fişi ile posta gönderme?
- 16. iPhone, NSURLConnection ile POST gönderme
- 17. Değişkenler ile NSLocalizedString Swift
- 18. Swift === ile nil
- 19. UILocalizedIndexedCollation ile Swift Selektörler
- 20. Swift ile JSONSerialization 3
- 21. gönderme?
- 22. Swift
- 23. Swift - Renkleri CGPoint ile karşılaştır
- 24. NSFetchedResultsController - Swift ile sıralayıcıları sırala -
- 25. Swift: UITableView ile Array Boyutu
- 26. Swift çıkışını ses ile kaydetme
- 27. 4 Swift ile İlgili Seçiciler.
- 28. xpath/css ile Swift/UIWebView
- 29. aşağıdaki sunucuya eposta Gönderme başarısız: Ben scala Playmework bir posta göndermeye çalıştığımda, hata aşağıdaki var smtp.gmail.com:25
- 30. UIBezierPath kullanarak: byRoundingCorners: Swift 2 ve Swift 3 ile
Ne denediniz? – Loko