using System.Net; //WebRequest&WebResponse
using System.Net.Mail; //Mail
using System.IO; //File
using System.Web;
using System.Threading;
private void zipFile()
{
try
{
//源文件路径
string filePath = @"C:/Test";
zipFileName = "压缩包";
//压缩后的文件路径
rarPath = @"C:/" + zipFileName + ".rar";
System.Diagnostics.Process process1 = new System.Diagnostics.Process();
process1.StartInfo.FileName = "Winrar.exe";
process1.StartInfo.CreateNoWindow = true;
//加密压缩文件
process1.StartInfo.Arguments = " a -p压缩密码 " + rarPath + " " + filePath;
process1.Start();
Thread.Sleep(3000); //Sleep 3S
}
catch (Exception ex)
{
}
}
private void sendMail_163(string toEmailAdr, string mailHead, string mailBody)
{
try
{
//163邮箱服务器
SmtpClient mailClient = new SmtpClient("smtp.163.com");
//Credentials登陆SMTP服务器的身份验证.
mailClient.Credentials = new System.Net.NetworkCredential("发件人用户名@163.com", "密码");
MailMessage message = new MailMessage(new MailAddress("发件人用户名@163.com"), new MailAddress(toEmailAdr));
//可以添加多个收件人
//message.Bcc.Add(new MailAddress("xxx@qq.com"));
//邮件主题 邮件内容
message.Subject = mailHead;
message.Body = mailBody;
//添加附件
Attachment att = new Attachment(@"C:/压缩包.rar");
message.Attachments.Add(att);
//发送邮件
mailClient.Send(message);
}
catch (Exception e1)
{
MessageBox.Show(e1.Message.ToString());
}
}