using System;
using System.Web;
using System.Web.Mail;
using System.IO;
namespace dbvt.Utils
{
///
/// Summary description for MailToFile.
///
public class MailToFile
{
public MailToFile()
{
//
// TODO: Add constructor logic here
//
}
private static string FileTimeString()
{
return System.DateTime.Now.Day.ToString() +
System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString();
}
public static bool Send(MailMessage msg)
{
try
{
string s = msg.To.Substring(1, msg.To.IndexOf("@") -1);
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("/dump/mail/" + FileTimeString() + s + ".htm"), FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(msg.Body + "\r\n");
sw.WriteLine("
TO: " + msg.To + "
");
sw.WriteLine("Subject: " + msg.Subject + "
");
sw.Close();
return true;
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
return false;
}
}
}
}