Skip to main content

Data Export Scripts

Data Export scripts can be used to customize the export process. An export script could be used to export extracted data to custom data structures in a database, or it could export data to a custom data source or like sending the data via Email.

 

The Following Example uses the C# code for sending the extracted data in the Email to the Id provided in the Input parameters.

C# Code

CODE
#r System.Net.dll
#r System.Net.Mail.dll

using System;
using System.Net;
using System.Net.Mail;

public bool ExportScript(ExportContext context) 
{
    public static void SendEmail(ExportContext context,string senderEmail, string recipientEmail, string subject, string body)
    {
    // Replace with your email provider's SMTP server, port, and credentials
    var smtpClient = new SmtpClient("smtp.gmail.com", 587);
    smtpClient.Credentials = new NetworkCredential("your_email@gmail.com", "your_password");
    smtpClient.EnableSsl = true;
    // Create a new email message
    var message = new MailMessage();
    message.From = new MailAddress(senderEmail);
    message.To.Add(new MailAddress(recipientEmail));
    message.Subject = subject;
    message.Body = body;

    // Send the email

    smtpClient.Send(message);
    context.Log("Email sent successfully!");

    }
   

    string senderEmail = "your_email@gmail.com";
    string recipientEmail = "recipient@example.com";
    string subject = "Test Email";
    string body = context.ExportFiles.GetDataFiles();
    SendEmail(senderEmail, recipientEmail, subject, body);
    return true;
}

The above code creates various functions but there is a Static function “ExportScript” as this is the main function under which all the other defined functions will be executed. The script execution starts from this main function. The return of the Static method “ExportScript” is Bool type only, where “True” means success and “Fail” means Failure of the script.

The Following Example uses Python for sending the extracted data in the Email to the Id provided in the Input parameters.

Python Code

CODE
#@smtplib.py

from se_scripting_utils import *
import smtplib
from email.mime.text import MIMEText

def send_email(sender_email, receiver_emails, subject, content):
    
    # Replace with your email provider's SMTP server, port, and credentials

    smtp_server = 'smtp.gmail.com'
    smtp_port = 587
    username = 'your_email@gmail.com'
    password = 'your_password'

    # Create a message

    message = MIMEText(content)
    message['From'] = sender_email
    message['To'] = ', '.join(receiver_emails)
    message['Subject'] = subject

    # Connect to the SMTP server

    with smtplib.SMTP(smtp_server, smtp_port) as server:
        server.starttls()
        server.login(username, password)
        server.sendmail(sender_email, receiver_emails, message.as_string())

def export_script(context: ExportContext):

    sender_email = 'your_email@gmail.com'
    receiver_emails = context.global_data.get_string("receiver_list")
    subject = context.global_data.get_string("subject")
    content = context.global_data.get_string("content")
    send_email(sender_email, receiver_emails, subject, content)
   
    return True
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.