0

I have ran some recorded script using selenium RC in visual studio(c#).

I have reports of those script readily.(i saved all the results in a text file)

Now, i want to send those reports in the form of mail to client through automation.

How to configure those settings and what all things will be required?

All the reports generated should be delivered to client.

Suggest the site or link where example is present.

Also give steps regarding configuration and settings.

Thank you..

Ranadheer Reddy
  • 4,202
  • 12
  • 55
  • 77

2 Answers2

5

This is more C# based than just a Selenium question.

There is an entire website devoted to explaining, in detail, how to send an email using C# and the System.Net.Mail namespace:

http://www.systemnetmail.com/

A simple example:

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

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
string fromPassword = "fromPassword";
string subject = "Subject";
string body = "Body";

var smtp = new SmtpClient
           {
               Host = "smtp.gmail.com",
               Port = 587,
               EnableSsl = true,
               DeliveryMethod = SmtpDeliveryMethod.Network,
               UseDefaultCredentials = false,
               Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
           };
using (var message = new MailMessage(fromAddress, toAddress)
                     {
                         Subject = subject,
                         Body = body
                     })
{
    smtp.Send(message);
}

All you would need to do is construct the message body by reading in the contents of the 'reports' you mentioned about.

Arran
  • 24,648
  • 6
  • 68
  • 78
4

Thank you for your code.

i found some code to send email with attachement.

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

public void email_send()
    {
        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
        mail.From = new MailAddress("your mail@gmail.com");
        mail.To.Add("to_mail@gmail.com");
        mail.Subject = "Test Mail - 1";
        mail.Body = "mail with attachment";

        System.Net.Mail.Attachment attachment;
        attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
        mail.Attachments.Add(attachment);

        SmtpServer.Port = 587;
        SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");
        SmtpServer.EnableSsl = true;

        SmtpServer.Send(mail);

    }

Read Sending email using SmtpClient for more information.

Thank you..

Ranadheer Reddy
  • 4,202
  • 12
  • 55
  • 77
  • 2
    This is indeed one way of doing it. Either attach the report as an attachment to your message or construct the message body from the contents of your report. – Arran May 29 '12 at 08:44