Support Topics Documentation Slack YouTube Blog

Email not send via Basic Emails API

I am trying to send emial via API as show documentation https://backendless.com/docs/js/email_send_basic_smails_api.html

I have set SMTP settings properly (the TEST passed).

When I try to send a email message I got response with status SCHEDULED.

What does mean status SCHEDULED? How to change the SMTP settings to immediate email sending?

Here is my TypeScript code to send an email:

  public sentOrder() {
    console.debug('Sending Order email');
    const body: Backendless.Bodyparts = {
      textmessage: null,
      htmlmessage: 'Check out this <b>awesome</b> code generation result'
    };
    Backendless.Messaging.sendEmail(
      'Email from Backendless', body,
      ['mato.krajcir@gmail.com'],
      ['assets/bmb/product/MarikaKlasik/BMB MARIKA KLASIK.jpg']
    ).then(response => {
      console.debug('Order email sent: ' + response);
      this.router.navigate(['../confirmation']);
    }).catch(error => {
      console.debug('Order email error during sendig' + error);
    });
  }

Hi @Martin_Krajcir1,

Backendless server handles email sending as an autonomous task. As a result, the final status of the email sent operation is not available right away. To retrieve the status, the client can make a separate API call:

Backendless.Messaging.getMessageStatus(messageId)
 .then(status => {
  })
 .catch(error => {
  })

where messageId is messageId field from response on email sending.
Method returns a JS object with the following structure:

{
  messageId:<messageId>,
  status:<status>,
  errorMessage:<errorMessage>
}

messageId is ID of the email for which the publishing status is retrieved.
The status in the response can be one of the following "published" , "scheduled" , "cancelled" , "failed" or "unknown" .
errorMessage contains a detailed error message when the status property is "failed" .

Your email should be sent already, please check spam folder maybe.

Regards,
Stanislaw

Hello @stanislaw.grin i use Backendless in Angular installed by:

npm i backendless

For sending email i use following function because I need to send my formated email withou template option. This function have only STRING result, there is not message id.

function sendEmail(subject: string, bodyParts: Backendless.Bodyparts, recipients: string[], attachments?: string[]): Promise<String>;

I checked my SPAM folder in email, and there is not any email.
I also checked the SENT folder of SMTP email account and is also empty.

Any idea?

Actually server responds with an object which contains message id, but for some reason JS SDK cuts it and return only message status… I think we’re going to fix this, but anyway, it should not block you now.
I just tested this method and I received the email immediately.
So I believe there’s something wrong with your SMTP server. It may block emails, or they are still in the sending queue…
You can also check email sending through ‘Send test email’ button under Email section.

Regards,
Stanislaw

Hi @stanislaw.grin i tried to SEND TEST EMAIL from pre-defined template. It wokrs fine!
Unfortunately I create new custom template and I did not received email by using SEND TEST EMAIL.

It seems something is wrong.

Could you please provide us your App ID?

@stanislaw.grin yes, good idea. Here is my app ID: 3551EF8F-C241-7579-FF0D-45ECE827AF00

Thank you.
I tried to send two emails to my email - one from custom templates (using ‘Send test email’ button) and one is simple - like you wrote in the first message.
Bot emails were received instantly. Not a spam, just inbox, everything is ok here.

I use gmail account.

So I think the problem is on side of your email client. I would recommend to contact their support with this situation.

Regards,
Stanislaw

@stanislaw.grin you are right there should be some other problem on email client side, beacause:
I tried to use multiple email addresses:

  • 2x different domain with Google G Suite - all OK
  • 1x free Gmail - OK
  • 1x free other Gmail - NOK (works only with predefined template and not with custom template). It is confusing.

I don’t understand it, but it should not be an error on Backendless side.

Thank you for your help

@stanislaw.grin I found the problem. My custom template has property {Users.address.country} Without this property is email send to my Gmail free mailbox.

But with this property (i did not set the value for testing) the email is not sent.

I will look into this…

@stanislaw.grin I think that if the Backendless cloud did not find the property (eg. in database table) or the attachments in uploaded files then it did not return ERROR message. unfortunately it return SCHEDULED and should be ERROR.

If property was not found, Backendless will not throw an error, it just ignores that dynamic property.
I tested again and I received email (without property, it’s ok):

Here is the code I ran:

const emailEnvelope = new Backendless.Messaging.EmailEnvelope()
emailEnvelope.setTo(['yourEmail@gmail.com'])

Backendless.Messaging.sendEmailFromTemplate('Marketing Template', emailEnvelope)

@stanislaw.grin finally I found the reason of my problem, see more detail:

  1. my email addres was already registered in Users table.
  2. in email template I used property {Users.address.country}
  3. the property address was not defined in Users table schema

So the email sendig proces failed during accesing to the data from Users table for specific email addres.

What should I expect
When there is missing data for template property in Users table schmea then should be returned ERROR or sent email without this property.

@stanislaw.grin my second problem for sendig email via API was, that I used attachments with whitespace in filename. I also tried to use + for whitespace (as is used for download link) but it seems to works only for file without space.

Hi @Martin_Krajcir1,

thank you for additional information you’ve found! You’re right, that’s where the problem was.
I have created two internal tickets for both problems, we will notify you here once its fixed.

Regards,
Stanislaw

You may reference these issues by IDs: BKNDLSS-22017, BKNDLSS-22018

1 Like

Hi @Martin_Krajcir1,

the problem with smart text is already resolved and will be released soon. We’ll let you know here once it’s released.

Regarding your second issue, we can not reproduce it.
Please make sure your attachments are not looks virus-like for your SMTP server (like .js files, .exe etc), because it may block such emails.

If you’re still experiencing problems with this, please let us know with which file we could reproduce this problem. Perhaps this is not about whitespace.

Thanks and regards,
Stanislaw

1 Like

Hi @stanislaw.grin,

thank you for info.

I tried reproduce the secont problem (whitespace in filename attachement) and it works fine, as expected.
Thank you.

1 Like