3

Is it possible to send an automatically generated email using my own email address to another email address of mine by clicking a button?

I tried to use MFMailComposeViewController but another view appeared. Can I do it without this view?

nobody
  • 19,814
  • 17
  • 56
  • 77
The Fonz
  • 207
  • 1
  • 4
  • 14
  • possible duplicate of [Possible to send automated email?](http://stackoverflow.com/questions/7630862/possible-to-send-automated-email) – A-Live Nov 13 '13 at 16:29
  • Look at the list of related questions to yours. This has been covered several times before. – rmaddy Nov 13 '13 at 17:23
  • possible duplicate of [How to send mail from iphone app without showing MFMailComposeViewController?](http://stackoverflow.com/questions/9427056/how-to-send-mail-from-iphone-app-without-showing-mfmailcomposeviewcontroller) – rmaddy Nov 13 '13 at 17:24

3 Answers3

4

You can do it only by creating own server-side mailer. On button clicking you have to send request with all needed data (email address, body, subject, etc) and server will send mail.

If You want send directly from app - MFMailComposeViewController is the only LEGAL way

in.disee
  • 1,102
  • 1
  • 7
  • 15
  • 2
    This is not true at all. It is perfectly legal to send an email from an app without `MFMailComposeViewController`. – rmaddy Nov 13 '13 at 17:25
  • I use in my app the skpsmtpmessage (https://github.com/jetseven/skpsmtpmessage). Works perfect, using gmail sender or a corporate SMTP server – Panayot Oct 02 '19 at 13:58
4

By default in iOS you can only use the MFMailComposeViewController, which uses the user's mail account. Therefore you cannot send fully automated mail messages (the user allways has to confirm/cancel).

libMailCore is a great iOS framework which allows you to generate and send mails without any user interferance. In that case you'll be using your own server/credentials (thus not the user mail account). There are apps in the App Store using mailcore, so i would guess it's legit.

Leijonien
  • 1,415
  • 14
  • 16
  • umm.. no. mailcore *cannot* be used to send emails on its own. You will still have to use `MFMailComposeViewController`.. check out the [api docs](http://libmailcore.com/mailcore2/api/Classes/MCOIMAPSession.html) of mailcore your self and you'll see they're all methods for fetching/downloading mail content.. not creating/sending them – abbood Jan 09 '14 at 15:51
  • 2
    No sir, you don't need 'MFMailComposeViewController', but you need your own smtp server. There's even sample code available on how to setup, and i'm using it myself (without 'MFMailComposeViewController')! – Leijonien Jan 10 '14 at 11:29
0

Yes there is a way using Swift-SMTP.

Send email Create a Mail object and use your SMTP handle to send it. To set the sender and receiver of an email, use the User struct:

let drLight = Mail.User(name: "Dr. Light", email: "drlight@gmail.com")
let megaman = Mail.User(name: "Megaman", email: "megaman@gmail.com")

let mail = Mail(
    from: drLight,
    to: [megaman],
    subject: "Humans and robots living together in harmony and equality.",
    text: "That was my ultimate wish."
)

smtp.send(mail) { (error) in
    if let error = error {
        print(error)
    }
}
TechFanatic
  • 1,218
  • 4
  • 13
  • 31