我在 Visual Studio(c#) 中使用 selenium RC 运行了一些录制的脚本。
我很容易收到这些脚本的报告。(我将所有结果保存在一个文本文件中)
现在,我想通过自动化将这些报告以邮件的形式发送给客户。
如何配置这些设置以及需要什么?
生成的所有报告都应交付给客户。
建议存在示例的站点或链接。
还提供有关配置和设置的步骤。
谢谢..
这比 Selenium 问题更基于 C#。
有一个完整的网站专门用于详细解释如何使用 C# 和 System.Net.Mail 命名空间发送电子邮件:
一个简单的例子:
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);
}
您需要做的就是通过阅读您提到的“报告”的内容来构建消息正文。
谢谢你的代码。
我找到了一些代码来发送带有附件的电子邮件。
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);
    }
阅读使用 SmtpClient 发送电子邮件以获取更多信息。
谢谢..