You can configure the SMTP service that MDrivenServer uses to send email from server-side jobs, including emails generated by a server-side ViewModel.
Before you begin
You need the SMTP connection details supplied by your email provider:
| Setting | What to obtain | Example from the test below |
|---|---|---|
| SMTP host | The provider's SMTP server name. | smtp.office365.com
|
| SMTP port | The port required by the provider. | 587
|
| Security | Whether the provider requires SSL/TLS. | SSL/TLS is enabled with -UseSsl in the PowerShell example.
|
| Login credentials | The account name and password, or provider-specific application-login credential, that authenticate to the SMTP service. | Entered through the credential prompt in the PowerShell example. |
| Sender address | The address recipients see in the message's From field. | sender@example.com
|
Keep the SMTP login credential separate from the sender address. The SMTP service authenticates the login credential, while a server-side ViewModel can provide the sender address for an individual message. Your provider must permit the authenticated account to send using that sender address.
Enter email settings in MDrivenServer
Configure the settings in the MDrivenServer control panel:
- Sign in to the MDrivenServer control panel.
- Open Running, then Model.
- Edit the email settings with the values from your SMTP provider.
- Save the settings.
- Send a test email using the PowerShell procedure below before relying on application email.
The MDrivenServer UI supports these email-related values:
| MDrivenServer setting | Use |
|---|---|
EmailHost
|
The SMTP host. |
EmailHostPWD
|
The password or SMTP credential secret. |
EmailFrom
|
The default sender email address. |
EmailFromPresentation
|
The presentation name associated with the default sender. |
Do not place an SMTP password directly in a model or source-controlled settings file. To keep sensitive values outside the MDrivenServer admin database, set an environment variable and enter its name enclosed in percent signs, for example %MySmtpPassword%, for supported MDrivenServer UI values. See SecureStore and environment variables for the supported settings and deployment examples.
Turnkey sites
For a MDriven Turnkey site, you can change email settings in the Portal or in the MDrivenServer email settings. Applying settings in the Portal updates the MDrivenServer settings. See Turnkey email settings for the Turnkey-specific behavior.
Configure provider authentication
Use the authentication method required by your SMTP provider. Some providers require an application-login credential rather than the password used for interactive web login.
For Gmail, the documented MDriven approach is to use Google's application login. The MDrivenServer login email is taken from the MDrivenServer settings; it is separate from the message's From value. If a server-side job omits or uses an unsupported sender address, Gmail can return an Incorrect login error. Consult your provider's current SMTP and application-login documentation before changing account security settings.
Test the SMTP service from PowerShell
Test the SMTP service from the machine that will send the email when possible. This isolates SMTP host, port, network access, and credentials from your MDrivenServer configuration.
The following example uses Office 365 values. Replace the sender, recipient, SMTP host, and port with your provider's values.
$From = "<sender address, not login>"
$To = "<destination email address>"
$Subject = "Test 1"
$Body = "This is what I want to say"
$SMTPServer = "smtp.office365.com"
$SMTPPort = "587"
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body `
-SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -Credential (Get-Credential)
PowerShell opens a Windows credential dialog. Enter the SMTP account credentials supplied by your provider. Do not enter the sender address as the login unless the provider uses the same value for both.
If the credential dialog fails in an Azure PowerShell prompt
In an Azure PowerShell prompt, the interactive password dialog can fail. The following pattern creates a PowerShell credential object instead. Replace all placeholder values before running it.
$username = 'user@url.se'
$password = ConvertTo-SecureString 'thepwd' -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
Send-MailMessage -From 'user@url.se' -Credential $psCred `
-To 'someone@somewhere.se' -Subject 'Test1000' -Body 'Body test1' `
-UseSsl -Port 587 -SmtpServer 'smtp.office365.com'
This command includes the password as plain text in the command input. Do not save this example with a real password in a script, repository, command history, or shared location. Use SecureStore and environment variables for deployed credentials.
Send email from your application
After SMTP testing succeeds, create or update a server-side ViewModel that sends the message. An action whose name starts with email triggers sending. The ViewModel supplies values such as to, from, subject, and body; it can also supply CC, BCC, and attachments.
For example, a ViewModel action named email can send a message to Customer Name<customer@example.com> with a subject and body defined by the ViewModel. For the exact required column names, multiple-recipient syntax, attachments, inline images, and send-result fields, see Emailing from an app using MDrivenServer.
The Password Reset Package also relies on these email settings. After installing that package, update the sender expression in its SS_ResetPassword ViewModel and verify that SMTP delivery works.
Troubleshooting
| Symptom | What to check |
|---|---|
| The PowerShell test cannot send email. | Verify the SMTP host, port, SSL/TLS requirement, credentials, and outbound network access with the email provider. |
| PowerShell sends successfully but MDrivenServer does not. | Compare the MDrivenServer email settings with the tested host, port, credentials, and sender. Confirm that an environment-variable reference resolves in the running application. |
| The provider reports an incorrect login. | Check that the MDrivenServer login email is configured in the server settings and that the provider's required application-login method is used. Also check the sender address used by the server-side job. |
| Recipients do not receive password-reset messages. | Confirm the MDrivenServer email settings, then review the sender configured in SS_ResetPassword as described in Password Reset Package.
|
