How to setup an Email Service in a Niagara Station (Gmail)
Configuring Gmail as an email service in Niagara 4 allows your Station to send email notifications, alarms, reports, and other automated communications. This guide provides comprehensive instructions for setting up Gmail integration with Niagara 4.
Overview
Niagara 4 includes an Email Service that can be configured to use Gmail's SMTP servers. This service enables automated email notifications for alarms, system events, scheduled reports, and custom applications.
Prerequisites
Before beginning, ensure you have:
- A Gmail account with access credentials
- A Gmail App Password (required for two-factor authentication)
- Administrative access to the Niagara Station
- Network connectivity to Gmail's SMTP servers (smtp.gmail.com)
Gmail Configuration Requirements
App Password Setup
Gmail requires an App Password for third-party applications like Niagara:
- Enable Two-Factor Authentication: Your Gmail account must have 2FA enabled
- Generate App Password: Create a dedicated app password for Niagara
- Save Credentials: Securely store the app password for use in Niagara
SMTP Server Details
Gmail SMTP configuration:
- SMTP Server: smtp.gmail.com
- Port: 587 (TLS) or 465 (SSL)
- Security: TLS/SSL encryption required
- Authentication: Required (username and app password)
Step-by-Step Configuration
Step 1: Generate Gmail App Password
- Log in to your Google Account
- Navigate to Google Account → Security
- Under Signing in to Google, ensure 2-Step Verification is enabled
- Scroll to App passwords
- Click App passwords (you may need to verify your password)
- Select Mail as the app
- Select Other (Custom name) as the device
- Enter "Niagara 4" as the custom name
- Click Generate
- Copy the 16-character app password (you'll need this for Niagara)
Step 2: Access Station Services
- Open Niagara Workbench
- Connect to your target Station
- In the Station tree, expand the Services folder
- Locate or create the Email Service
Step 3: Create Email Service (if not exists)
If an Email Service doesn't exist:
- Right-click on Services
- Select New → Service → Email Service
- Enter a name (e.g., "Gmail Service")
- Click OK
Step 4: Configure SMTP Settings
- Right-click on the Email Service
- Select Properties
- Navigate to the SMTP tab or Configuration section
Step 5: Enter SMTP Server Details
Configure the SMTP server settings:
- SMTP Host:
smtp.gmail.com - SMTP Port:
587(for TLS) or465(for SSL) - Use TLS: Enable this checkbox (for port 587)
- Use SSL: Enable this checkbox (for port 465, use instead of TLS)
- Require Authentication: Enable this checkbox
Step 6: Configure Authentication
Enter Gmail credentials:
- Username: Your full Gmail address (e.g.,
yourname@gmail.com) - Password: The 16-character App Password generated in Step 1
- From Address: Your Gmail address (e.g.,
yourname@gmail.com) - From Name: Display name for sent emails (e.g., "Niagara Station")
Step 7: Configure Advanced Settings (Optional)
Set additional email service parameters:
- Connection Timeout: 30 seconds (default)
- Command Timeout: 30 seconds (default)
- Maximum Retries: 3 (default)
- Retry Interval: 5 seconds (default)
Step 8: Test Email Configuration
- In the Email Service properties, locate the Test button
- Click Test to send a test email
- Enter a test recipient email address
- Click Send Test Email
- Check the recipient inbox for the test email
- Review any error messages if the test fails
Step 9: Enable the Email Service
- Ensure the Email Service is Enabled (check the Enabled checkbox)
- Click OK to save configuration
- The service will start automatically
Step 10: Verify Service Status
- Check the Email Service status in the Station tree
- Status should show as Running or Online
- Review the service log for any errors
Configuration Examples
Basic Gmail Configuration
SMTP Host: smtp.gmail.com
SMTP Port: 587
Use TLS: Enabled
Require Authentication: Enabled
Username: yourname@gmail.com
Password: [16-character App Password]
From Address: yourname@gmail.com
From Name: Niagara Station
SSL Configuration Alternative
SMTP Host: smtp.gmail.com
SMTP Port: 465
Use SSL: Enabled
Require Authentication: Enabled
Username: yourname@gmail.com
Password: [16-character App Password]
From Address: yourname@gmail.com
Using the Email Service
Sending Emails from Applications
Once configured, you can send emails from Niagara applications:
// Example: Send email notification
emailService.sendEmail({
to: 'recipient@example.com',
subject: 'System Alert',
body: 'This is a test email from Niagara Station'
});
Configuring Alarm Email Notifications
- Navigate to Alarm Service in the Station
- Configure alarm email recipients
- Set email notification rules
- Test alarm email delivery
Scheduled Email Reports
- Configure report generation schedules
- Set email delivery for reports
- Configure report recipients
- Test report email delivery
Troubleshooting
Authentication Failures
If authentication fails:
- Verify App Password: Ensure you're using the App Password, not your regular Gmail password
- Check 2FA: Verify two-factor authentication is enabled on your Gmail account
- Username Format: Ensure username is the full email address
- Password Format: Verify the 16-character App Password is entered correctly (no spaces)
Connection Timeouts
If experiencing connection timeouts:
- Check Network: Verify network connectivity to smtp.gmail.com
- Firewall Settings: Ensure port 587 or 465 is not blocked
- Port Selection: Try port 465 (SSL) if 587 (TLS) fails
- Timeout Values: Increase connection timeout values
Emails Not Sending
If emails are not being sent:
- Service Status: Verify Email Service is enabled and running
- Check Logs: Review Email Service logs for error messages
- Test Configuration: Use the test email function to verify settings
- Recipient Validation: Verify recipient email addresses are valid
Gmail Security Warnings
If Gmail blocks emails:
- Review Gmail Security: Check Gmail account security settings
- App Password: Ensure App Password is correctly configured
- Less Secure Apps: Note that Gmail no longer supports "Less Secure Apps"
- Account Review: Review Gmail account for security alerts
Security Best Practices
Credential Management
- Use App Passwords: Always use App Passwords, never regular passwords
- Secure Storage: Store credentials securely
- Regular Rotation: Periodically rotate App Passwords
- Access Control: Limit access to Email Service configuration
Network Security
- Use TLS/SSL: Always enable encryption (TLS or SSL)
- Firewall Rules: Configure firewall rules appropriately
- Network Monitoring: Monitor email service network activity
Email Content
- Sensitive Data: Avoid sending sensitive data via email
- Email Validation: Validate email addresses before sending
- Rate Limiting: Configure appropriate sending rates
Related Topics
- How to set two-factor authentication in a Niagara Station (Gauth)
- How to setup LDAP integration in a Niagara Station
Additional Resources
- Gmail App Passwords Documentation
- Niagara 4 Email Service Guide
- SMTP Configuration Best Practices