Skip to content

Easy way to detect installed email clients and allow the user to choose one when sending an email

License

Notifications You must be signed in to change notification settings

GigabiteLabs/SYEmailHelper

 
 

Repository files navigation

SYEmailHelper

Easily detect installed email clients and allow the user to choose one when sending an email.

I use it to quickly add a "Contact me" feature in my apps. This will detect a list of SYEmailService, representing:

  • native in-app composer
  • third party apps
  • last resort: copy email address to clipboard, to let your user send via an unsupported app

If there are no items in the list the completion block is called with an error: SYEmailHelperErrorDomain, code SYEmailHelperErrorCode_NoServiceAvailable.

If the use selected a third party app that couldn't be opened an error will be generated too: SYEmailHelperErrorCode_CouldntOpenApp.

If a single supported service is available it will automatically be launched.

If multiple supported services are available an action sheet will be displayed.

You can:

  • disable the "copy to pasteboard" option
  • change the text for "copy to pasteboard" option
  • change the text for "cancel" option

Example:

    PasteboardEmailService.name = "Copy email address to pasteboard"
    
    EmailHelper.shared.showCopyToPasteBoard = true
    EmailHelper.shared.actionSheetTitle = "Which app you wanna use?"
    EmailHelper.shared.actionSheetMessage = "We support some third party apps, native email client and copying to clipboard if your favorite app is not supported"
    EmailHelper.shared.actionSheetCancelButtonText = "Meh..."
    
    EmailHelper.shared.presentActionSheet(
        address: emailField.text,
        subject: subjectField.text,
        body: bodyField.text,
        presentingViewController: self,
        sender: sender)
    { (canceled, service, error) in
        if (canceled) {
            self.completionLabel.text = "User cancelled"
        }
        else if let service = service, let error = error {
            self.completionLabel.text = String(format: "Service %@ encountered error: %@", service.name, error.localizedDescription)
        }
        else if let error = error {
            self.completionLabel.text = String(format: "Encountered error: %@", error.localizedDescription)
        }
        else if let service = service {
            self.completionLabel.text = String(format: "No error, used service %@", service.name)
        }
    }

How To Install

Using Cocoapods

  1. Add the following to your project Podfile:
pod 'SYEmailHelper', '~>  2.2.0'
  1. Open a new terminal

  2. cd to the root of your project directory

  3. run pod install from the command line


Using Swift Package Manager

  1. Open your project and click on the project name in project navigator
  2. Under the “Project” section click your project name, then click “Package Dependecies”
  3. Click the “+” button, and search for https://github.com/dvkch/SYEmailHelper.git
  4. Once the package is found, be sure to select “exact version” and enter version number “2.2.0”
  5. Press enter and the package will be downloaded and integrated into your Xcode Project

Import the package (both SPM & Cocoapods)

At the top of any .swift file in your project add:

import SYEmailHelper

Don't forget ============

You'll need to add the list of supported apps inside your Info.plist. Here are the needed items for the current list of supported apps.

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>googlegmail</string>
	<string>inbox-gmail</string>
	<string>ms-outlook</string>
	<string>readdle-spark</string>
</array>

Screenshots

ActionSheet

Examples

You can open both SPM and Cocoapods example projects, as well as the package itself, by opening the repo workspace.

Simply:

  1. Clone this repository

  2. Open the repository folder

  3. Open the SYEmailHelper.xcworkspace with Xcode, which is located in the root directory of this repo


License

Use it as you like in every project you want, redistribute with mentions of my name and don't blame me if it breaks :)

-- dvkch

About

Easy way to detect installed email clients and allow the user to choose one when sending an email

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 94.9%
  • Ruby 5.1%