How to send allure report in mail

To send an Allure report via email, you can use a combination of Allure's reporting capabilities and a email sending library. Here's a step-by-step guide:

Prerequisites

  1. You have Allure installed and configured in your project.
  2. You have a email sending library installed in your project (e.g., JavaMail, SendGrid, etc.).

Step 1: Generate the Allure report

Run your tests using Allure, and it will generate a report in the specified format (e.g., HTML, JSON, etc.).

Step 2: Convert the report to a format suitable for email

You can use Allure's API to convert the report to a format suitable for email. For example, you can use the allure command-line tool to generate a HTML report and then convert it to a PDF using a library like Apache PDFBox.

Step 3: Send the report via email

Use your email sending library to send the report as an attachment. Here's an example using JavaMail:

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class SendAllureReportViaEmail {
    public static void main(String[] args) throws Exception {
        // Set up email settings
        String from = "[email protected]";
        String to = "[email protected]";
        String subject = "Allure Report";
        String body = "Please find the Allure report attached.";

        // Set up the report file
        File reportFile = new File("path/to/allure/report.pdf");

        // Create a mail session
        Properties props = new Properties();
        props.put("mail.smtp.host", "your-smtp-host");
        props.put("mail.smtp.port", "your-smtp-port");
        Session session = Session.getInstance(props);

        // Create a message
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject(subject);
        message.setText(body);

        // Add the report as an attachment
        message.attachFile(reportFile);

        // Send the message
        Transport.send(message);
    }
}

Step 4: Schedule the email sending

You can schedule the email sending using a scheduler like Quartz or Apache Airflow. This way, you can automate the process of sending the Allure report via email after each test run.

That's it! With these steps, you should be able to send an Allure report via email.