Is there any framework that will allow me to send email without going through a GUI?
Asked
Active
Viewed 2,168 times
2
-
1You need to provide more information on the issue you are facing. – Sid Malani Nov 25 '11 at 21:53
-
its very clear i want to send email without showing ui... i know that using apple mfmessage framework and doing it will be rejected – orthehelper Nov 25 '11 at 21:54
-
You'll find a fantastic code sample on the accepted answer here to send a background email: http://stackoverflow.com/questions/6284599/mfmailcomposeviewcontroller-question-locking-the-fields – Luke Nov 25 '11 at 21:58
3 Answers
1
Add this framework to your project and then use my Swift class:
class EmailSender : SKPSMTPMessageDelegate {
private init() {}
static let sharedInstance = EmailSender();
func sendEmail(email : String, subject : String, message : String) {
let EMAIL_FROM = "test@gmail.com";
let EMAIL_PASS = "TestPassword";
let SMTP_SERVER = "smtp.gmail.com";
let EMAIL_TO = email;
let emailMessage = SKPSMTPMessage();
emailMessage.delegate = self;
emailMessage.fromEmail = EMAIL_FROM;
emailMessage.toEmail = EMAIL_TO;
emailMessage.relayHost = SMTP_SERVER;
emailMessage.requiresAuth = true;
emailMessage.login = EMAIL_FROM;
emailMessage.pass = EMAIL_PASS;
emailMessage.subject = subject;
emailMessage.wantsSecure = true;
let plainMsg = [
kSKPSMTPPartContentTypeKey : "text/plain",
kSKPSMTPPartMessageKey : message,
kSKPSMTPPartContentTransferEncodingKey : "8bit"
];
emailMessage.parts = [plainMsg];
emailMessage.send();
}
//MARK SKPSMTPMessageDelegate
@objc func messageSent(_ message: SKPSMTPMessage!) {
}
@objc func messageFailed(_ message: SKPSMTPMessage!, error: Error!) {
}
}

Nikolay Khramchenko
- 421
- 5
- 9
1
You should check out the SKPSMTPMessage framework. This allows you to send emails in the background. http://code.google.com/p/skpsmtpmessage/ It is not possible to do so yet, unless you code around MFMailComposeViewController which would presumably get your app rejected from the store (iOS5.0)

max_
- 24,076
- 39
- 122
- 211
1
If you don't need to have the email sent from the iPhone users mail app, you could offload the action to a server and have the server mail it on the users behalf.
The only problem with this is that you may have spam issues depending on what service you use (Mail Chimp etc...).