没有GUI发送电子邮件

时间:2011-11-25 21:51:11

标签: objective-c ios cocoa-touch email

是否有任何框架可以让我在不通过GUI的情况下发送电子邮件?

3 个答案:

答案 0 :(得分:1)

您应该查看SKPSMTPMessage框架。这允许您在后台发送电子邮件。 http://code.google.com/p/skpsmtpmessage/除非你在MFMailComposeViewController周围进行编码,否则你的应用程序可能会从商店中被拒绝(iOS5.0)

答案 1 :(得分:1)

如果您不需要从iPhone用户邮件应用程序发送电子邮件,您可以将操作卸载到服务器并让服务器代表用户邮寄它。

唯一的问题是,根据您使用的服务(Mail Chimp等等),您可能会遇到垃圾邮件问题。

答案 2 :(得分:1)

this框架添加到项目中,然后使用我的Swift类:

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!) {

    }

}