A simple library enabling non-obtrusive mailing from React Native!
TODO
TODO
Install this package with with npm
or yarn
!
This library has a peer-dependency on react-native ^0.47.0
.
Make sure to run pod install
inside of your project's ios folder! This library depends on mailcore2-ios
for the bridge between React Native and iOS.
No extra steps are necessary for Android, just install and go!
See docs
import RNSmtpMailer from "react-native-smtp-mailer";
RNSmtpMailer.sendMail({
// Required fields
username: "[email protected]",
password: "password-for-above-mail",
from: "address-sending-this-mail", // Probably the same as `username`
recipients: ["[email protected], [email protected]"],
subject: "subject",
htmlBody: "<h1>header</h1><p>body</p>",
// Optional fields
mailhost: "smtp.gmail.com", // Defaults to "smtp.gmail.com" if nothing is specified
port: 465, // Defaults to 465 if nothing is specified
ssl: true, // defaults to true if nothing is specified. If ssl is set to false, TLS is enabled.
cc: ["[email protected]", "[email protected]"],
bcc: ["[email protected]", "[email protected]"],
attachmentPaths: [
RNFS.ExternalDirectoryPath + "/image.jpg",
RNFS.DocumentDirectoryPath + "/test.txt",
RNFS.DocumentDirectoryPath + "/test2.csv",
RNFS.DocumentDirectoryPath + "/pdfFile.pdf",
RNFS.DocumentDirectoryPath + "/zipFile.zip",
RNFS.DocumentDirectoryPath + "/image.png"
],
attachmentNames: [ // Names of the attached files
"image.jpg",
"firstFile.txt",
"secondFile.csv",
"pdfFile.pdf",
"zipExample.zip",
"pngImage.png"
],
attachmentTypes: ["img", "txt", "csv", "pdf", "zip", "img"], // Necessary to preserve the order as the files in attachmentPaths
})
.then(success => console.log(success))
.catch(err => console.log(err));
RNFS is from react-native-fs library, used just to demonstrate a way of accessing files on the phones local filesystem.
type: String
The username of the email account to send the mail from. The library needs this to authenticate against the mail server.
type: String
Provide the password for the host email account. The library needs this to authenticate against the mail server.
type: String
Specify from which email to send the mail from. This is probably the same as username
.
type: String[]
All the recievers of your mail. You can specify one or more recievers in the list.
type: String
The visible subject of the mail
type: String
The text provided in the mail. As the name of this fields conveys you can specify custom html to be displayed as the message of your email.
type: String
default value: "smtp.gmail.com"
The mail server that hosts the username
email address. Depending on your situation you might need to
change this, e.g.if you are using Microsoft Outlook.
type: Integer (Javascript Number)
default value: 465
The port which the mail server listens to. Default for Google's mail servers is port 465. Again, this might be dependant on your specific mail server.
type: boolean
default value: true
SSL is recommended to have enabled. It allows for a secure encrypted communication between the mobile client and the mail server which is authenticated against.
type: String[]
default value: []
Allows to specify recievers which should recieve a copy of the mail.
type: String[]
default value: []
Allows to specify recievers which should be concealed / not visible to other people in the communication.
type: String[]
default value: []
Paths to files on the local file system.
type: String[]
default value: []
Only used in Android, these are renames of original files. In iOS filenames will be same as specified in path. In iOS-only application, attachmentNames
can be left unprovided or empty.
type: String[]
default value: []
Only used in Android.
In iOS-only application, you may leave attachmentTypes
empty. Generally every image (either jpg, png, jpeg etc..) file should have "img", and every other file should have its corresponding type.
Add the following into android/app/proguard-rules.pro
-dontshrink
-keep class javax.** {*;}
-keep class com.sun.** {*;}
-keep class myjava.** {*;}
-keep class org.apache.harmony.** {*;}
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-dontwarn javax.activation.**