cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Alert subscription stopped sending emails

gsee
1-Newbie

Alert subscription stopped sending emails

Hi,

I have a subscription to an alert that has stopped sending emails. The subscription to AnyAlert is enabled on a Thing Template, and the alerts are enabled on the appropriate Things. The subscription code is:

sensorMessage = eventData.description + " at Sensor " + me.SensorID;

linkMessage = "You can view the status of all sensors locations here."

var params = {

    cc: "username@gmail.com",

    subject: me.SensorName + " alert" /* STRING */,

    from: "username@company.com" /* STRING */,

    to: me.ThingManager.smsAddress,

    body: "At "+ eventTime + " " + sensorMessage + "<br>" + linkMessage,

};

Things["PasswordMailServer"].SendMessage(params);

The alerts were sending emails correctly a week ago. I acknowledged a few of the alerts in the monitor, but not all, and added several new alerts that are still not sending emails, although I can see the new alerts in the Alert Summary.

I'd appreciate any help!

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
emoreira
12-Amethyst
(To:gsee)

I think you could use the GetPropertyValues from the User Object once you retrieve the user name. Maybe it is not the elegant way to do it, but I did it and it did the trick:

var userProperties = Users[me.user].GetPropertyValues();

logger.warn(userProperties.emailAddress);

logger.warn(userProperties.smsAddress);

Where me.user is a variable of the type USERNAME that I used to select an user.

Not sure if this is your exact use case tough.

***UPDATED***

Actually you don't even need the Get Property Values call. Just make it an indirect reference:

logger.warn(Users[me.user].emailAddress);

logger.warn(Users[me.user].smsAddress);

Cheers

Ewerton

View solution in original post

7 REPLIES 7
emoreira
12-Amethyst
(To:gsee)

Hi Gloria,

Do you see any error in the logger (Monitoring->Logs->Script) ?

What would  do is to add a logger.warn("Executed"); statement in the code just to figure out if the service is running and it is not the Mail Server that is holding the message from being sent (if you haven't done it yet)

Cheers

Ewerton

gsee
1-Newbie
(To:emoreira)

Thanks Ewerton. That narrowed it down a lot.

I added a couple logger statements, and it turns out the me.ThingManager.smsAddress is coming back undefined. Any suggestions on how to pull the sms or email for a user defined as a property of each Thing? I can get it to work for a hardcoded email or sms address (or hard coded user) but that's not scalable to multiple users.

emoreira
12-Amethyst
(To:gsee)

I think you could use the GetPropertyValues from the User Object once you retrieve the user name. Maybe it is not the elegant way to do it, but I did it and it did the trick:

var userProperties = Users[me.user].GetPropertyValues();

logger.warn(userProperties.emailAddress);

logger.warn(userProperties.smsAddress);

Where me.user is a variable of the type USERNAME that I used to select an user.

Not sure if this is your exact use case tough.

***UPDATED***

Actually you don't even need the Get Property Values call. Just make it an indirect reference:

logger.warn(Users[me.user].emailAddress);

logger.warn(Users[me.user].smsAddress);

Cheers

Ewerton

gsee
1-Newbie
(To:emoreira)

Awesome! Both worked, but the indirect reference is just what I was trying to get working.

Thank you

fmanniti
9-Granite
(To:gsee)

Sorry for re-opening this post but I am having the same issue.

I have a thing with a property called isSeismic (boolean); if it is true, an alert should be triggered and I have a subscription which runs my service for sending email.

This is the path.

The event comes  --> Stream add a entry  --> at stream entry an event is triggered to Thing  --> Thing has subscription to call EmailThingSender --> EmailThingSender sends email.

My code is:

    var subject = Resources["RuntimeLocalizationFunctions"].GetEffectiveToken({token: 'NewAlertNotification'});

    var configurator = Things[structureName].Configurator;

    var configuratorProperties = Users[configurator].GetPropertyValues();

    var confEmail = configuratorProperties.emailAddress;

    var params = {

        to: confEmail,

        subject: subject,

        from: 'alert.notification@gmail.com',

        body: getBodyMail()

    };

    Things["EmailManagement"].SendMessage(params);

If I manually change the property Value (I switch isSeismic to true), the email notificator works, but if I do it as an event subscription, it doesn't

emoreira
12-Amethyst
(To:fmanniti)

Hi Fabio, is there any entry in the logs?

Cheers

Ewerton

Sorry for not re-answering but, I don't know what I did exactly but now it works fine

Top Tags