Uipath send smtp mail message

UIPath provides a built-in activity called "Send Email" that allows you to send an email using SMTP (Simple Mail Transfer Protocol). Here's a step-by-step guide on how to use it:

Prerequisites:

  1. You need to have a valid SMTP server settings (host, port, username, and password) to send the email.
  2. Make sure you have the "Send Email" activity installed in your UIPath project. If not, you can install it from the "Activities" panel.

Steps to send an SMTP email message:

  1. Drag and drop the "Send Email" activity from the "Activities" panel to your workflow.
  2. Double-click the activity to open its properties.
  3. In the "Send Email" activity properties, enter the following information:
    • To: The recipient's email address.
    • Subject: The subject of the email.
    • Body: The body of the email.
    • SMTP Server: The hostname or IP address of your SMTP server.
    • SMTP Port: The port number used by your SMTP server (usually 25, 587, or 465).
    • Username: Your SMTP server username.
    • Password: Your SMTP server password.
  4. Click "OK" to save the changes.
  5. Run the workflow to send the email.

Example code:

Here's an example code snippet that demonstrates how to send an SMTP email message using UIPath:

using UiPath.Activities;
using System.Net.Mail;

public class SendEmailActivity : Activity
{
    [Input("To", "The recipient's email address")]
    public string To { get; set; }

    [Input("Subject", "The subject of the email")]
    public string Subject { get; set; }

    [Input("Body", "The body of the email")]
    public string Body { get; set; }

    [Input("SMTP Server", "The hostname or IP address of your SMTP server")]
    public string SmtpServer { get; set; }

    [Input("SMTP Port", "The port number used by your SMTP server")]
    public int SmtpPort { get; set; }

    [Input("Username", "Your SMTP server username")]
    public string Username { get; set; }

    [Input("Password", "Your SMTP server password")]
    public string Password { get; set; }

    protected override void Execute(ActivityExecutionContext context)
    {
        using (var mail = new MailMessage())
        {
            mail.To.Add(To);
            mail.Subject = Subject;
            mail.Body = Body;

            using (var client = new SmtpClient())
            {
                client.Host = SmtpServer;
                client.Port = SmtpPort;
                client.EnableSsl = true;
                client.Credentials = new NetworkCredential(Username, Password);

                client.Send(mail);
            }
        }
    }
}

Note that this code snippet is just an example and you should modify it to fit your specific requirements. Additionally, make sure to handle any exceptions that may occur during the email sending process.