angelos3lex / react-native-smtp-mailer

Send emails by connecting to smtp server+attachments, using android javamail and ios mailcore2
39 stars 32 forks source link

Undefined is not an object... #1

Closed bsdt-snelson closed 5 years ago

bsdt-snelson commented 5 years ago

After following all installation procedures for Android I get : TypeError: undefined is not an object (evaluating '_reactNativeSmtpMailer2.default.sendMail')

I tried a number of different smtp relays I have access to and they all returned the same error... perhaps an installation issue?

angelos3lex commented 5 years ago

@bsdt-snelson First, please make sure that everything in manual setup is performed successfully using the link command. If it didn't work, then you should follow manual installation. Then make sure you import the module in your js file:

import RNSmtpMailer from "react-native-smtp-mailer";

If everything is done correctly, but issue persists, try running the example and let me know if this error is still happening. It is an installation issue according to error message, so smtp credentials are not the problem...

bsdt-snelson commented 5 years ago

Yes, the manual installation process was followed. Here is my code:

import React, {Component} from 'react'; import {Container, Content, Text} from 'native-base'; import {Alert} from 'react-native'; import myPerms from '../json/myPerms.json'; import containerPerms from '../json/containers.json'; import {ReactNativeAD, ADLoginView} from 'react-native-azure-ad' import RNSmtpMailer from 'react-native-smtp-mailer'; ….. RNSmtpMailer.sendMail({ mailhost: "smtp.gmail.com", port: "465", ssl: true, //if ssl: false, TLS is enabled,note: in iOS TLS/SSL is determined automatically, so either true or false is the same username: "xxxs@gmail.com", password: "mypasswordhere", from: "xxxx@yyyy.com", recipients: " xxxx@yyyy.com ", subject: "test smtp", htmlBody: "

header

body

", }) .then(success => console.log("EMAIL SENT: " + success)) .catch(err => console.log("EMAIL ERROR: " + err));

I did modify the android\build.gradle file as such: dependencies { compile "com.facebook.react:react-native:+" // From node_modules compile fileTree(dir: "libs", include: ["*.jar"]) }

And I am running react-native version 0.55.4

From: Angelos Lechouritis [mailto:notifications@github.com] Sent: Tuesday, September 18, 2018 10:09 AM To: angelos3lex/react-native-smtp-mailer Cc: Shawn Nelson; Mention Subject: Re: [angelos3lex/react-native-smtp-mailer] Undefined is not an object... (#1)

@bsdt-snelsonhttps://github.com/bsdt-snelson First, please make sure that everything in manual setup is performed successfully using the link command. If it didn't work, then you should follow manual installation. Then make sure you import the module in your js file:

import RNSmtpMailer from "react-native-smtp-mailer";

If everything is done correctly, but issue persists, try running the example and let me know if this error is still happening. It is an installation issue according to error message, so smtp credentials are not the problem...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/angelos3lex/react-native-smtp-mailer/issues/1#issuecomment-422431631, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKz50E26YgCIgjN-WH-bUCdmWWyb358sks5ucQxugaJpZM4WuFel.

This message, including any attachments, is for the designated recipient only and/or Hallmark Cards, Inc. employees. It may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail, disclosure of the information, or distribution by you is prohibited.

angelos3lex commented 5 years ago

@bsdt-snelson your android/settings.gradle should contain:

...
include ':react-native-smtp-mailer'
project(':react-native-smtp-mailer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smtp-mailer/android')

your android/app/build.gradle should contain: //Not android/build.gradle as you mentioned

dependencies {
    implementation project(':react-native-smtp-mailer')
    implementation fileTree(dir: "libs", include: ["*.jar"])
... //everything else
}

And in MainApplication.java, import and package:

import com.reactlibrary.RNSmtpMailerPackage;
...
 new RNSmtpMailerPackage() // in getPackage() list

*EDIT: since you also do not want to add attachments, add them as empty array like this:

 RNSmtpMailer.sendMail({
      mailhost: "smtp.gmail.com",
      port: "465",
      ssl: true,
      username: "xxxs@gmail.com",
      password: "mypasswordhere",
      from: "xxxx@yyyy.com",
      recipients: " xxxx@yyyy.com ",
      subject: "test smtp",
      htmlBody: "<h1>header</h1><p>body</p>",
      attachmentPaths: [],
      attachmentNames: [],
      attachmentTypes: []
      })
      .then(success => console.log("EMAIL SENT: " + success))
      .catch(err => console.log("EMAIL ERROR: " + err));
bsdt-snelson commented 5 years ago

“And in MainApplication.java, import and package:

import com.reactlibrary.RNSmtpMailerPackage;

...

new RNSmtpMailerPackage() // in getPackage() list “

Helped as I don’t believe that code in the documentation on the Github page- if it is I missed it.

However, there is now another error: “ReferenceError: Can't find variable: RNFS” likely due to the fact that RNFS used in the attachmentPaths property is not defined in the documentation. Once it is defined it works fine.

Thanks! Shawn

From: Angelos Lechouritis [mailto:notifications@github.com] Sent: Tuesday, September 18, 2018 11:17 AM To: angelos3lex/react-native-smtp-mailer Cc: Shawn Nelson; Mention Subject: Re: [angelos3lex/react-native-smtp-mailer] Undefined is not an object... (#1)

@bsdt-snelsonhttps://github.com/bsdt-snelson your android/settings.gradle should contain:

...

include ':react-native-smtp-mailer'

project(':react-native-smtp-mailer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smtp-mailer/android')

your android/app/build.gradle should contain: //Not android/build.gradle as you mentioned

dependencies {

implementation project(':react-native-smtp-mailer')

implementation fileTree(dir: "libs", include: ["*.jar"])

... //everything else

}

And in MainApplication.java, import and package:

import com.reactlibrary.RNSmtpMailerPackage;

...

new RNSmtpMailerPackage() // in getPackage() list

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/angelos3lex/react-native-smtp-mailer/issues/1#issuecomment-422455347, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKz50P7QX27Cqd7qDf5wyVXlX9dz2eLvks5ucRyOgaJpZM4WuFel.

This message, including any attachments, is for the designated recipient only and/or Hallmark Cards, Inc. employees. It may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail, disclosure of the information, or distribution by you is prohibited.

angelos3lex commented 5 years ago

@bsdt-snelson It's the first step in manual installation of Android. Yeah, RNFS is from react-native-fs library, and it is used in documentation just to show a way of accessing files in the phone, it is not necessary. Glad that it worked!

ahtesham-shah commented 5 years ago

i am even getting same error please help me

ahtesham-shah commented 5 years ago

when i calls a method by clicking button it directly gives red coloured error sendMail is not defined

shuffledex commented 5 years ago

same error here