Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

c# - Sending mail through automation (c # ) [mail with attachement]

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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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("[email protected]", "From Name");
var toAddress = new MailAddress("[email protected]", "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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...