- Created by SS Doc Editor, last modified on Jan 08, 2024
The new SMTP component comes with a code to send an email to a recipient. The sample code is below:
using System;
using StresStimulus.Extensibility;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
class MySMTPComponent : ActionComponent //Do not rename Class
{
public MySMTPComponent() {
//Do not edit this section.
}
/////////////////////////////////////////////////////////////////////////////////////////////
//
// 1. Enter you SMTP Server host, port, ssl setting, and credentials
// 2. Ender the email sender, recipient, subject, body
//
/////////////////////////////////////////////////////////////////////////////////////////////
const string SMTP_HOST = ""; //Your SMTP hostname.
const int SMTP_PORT = 25; //SMTP port. Default is 25
const bool ENABLE_SSL = false; //If SMTP requires SSL
const string USERNAME = ""; //Your SMTP Username
const string PASSWORD = ""; //Your SMTP Password
const string SENDER = ""; //Email sender
const string RECIPIENT = ""; //Email recipient
const string SUBJECT = ""; //Email subject
const string BODY = ""; //Email body
#region Start/Stop Test
SmtpClient m_smtpClient;
/// <summary>
/// Fired when test started.
/// </summary>
public override void OnTestStart() {
m_smtpClient = new SmtpClient();
m_smtpClient.Host = SMTP_HOST;
m_smtpClient.Port = SMTP_PORT;
m_smtpClient.EnableSsl = ENABLE_SSL;
m_smtpClient.Credentials = new NetworkCredential(USERNAME, PASSWORD);
}
/// <summary>
/// Fired when test ends.
/// </summary>
public override void OnTestEnd() {
}
#endregion
public void SendEmail(ActionArgs arg) {
try {
MailMessage email = new MailMessage();
email.Sender = new MailAddress(SENDER);
email.Subject = SUBJECT;
email.Body = BODY;
email.To.Add(RECIPIENT);
m_smtpClient.Send(email);
}
catch (Exception ex) {
arg.IsError = true;
arg.ErrorMessage = ex.Message;
}
}
}
Add the following to the code:
- The SMTP server host, port, and credentials
- The sender and recipient email addresses
- The email subject and body
- No labels
Overview
Content Tools



