|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Request.SaveAs(@"D:\Emailer\RQlog.txt", true);
string sTo = txtTo.Value;
string sFrom = txtFrom.Value;
string sSubject = txtSubject.Value;
string sBody = txtBody.Value;
string sFileName=string.Empty;
//WriteToLog("from page load txtFrom=" + txtFrom.Value + " files=" + Request.Files.Count);
if (fileToUpload.PostedFile != null)
{
sFileName = @"D:\Emailer\"
+ Path.GetFileNameWithoutExtension(fileToUpload.PostedFile.FileName)
+ DateTime.Now.ToString("yyyyMMddHHmmss")
+ Path.GetExtension(fileToUpload.PostedFile.FileName);
fileToUpload.PostedFile.SaveAs(sFileName);
}
//Emailing code goes here
if (sFrom.Length > 0 && sTo.Length > 0 && sSubject.Length > 0 && sBody.Length > 0)
{
MailMessage mail = new MailMessage(sFrom, sTo, sSubject, sBody);
Attachment mailAttach = new Attachment(sFileName);
mail.Attachments.Add(mailAttach);
SmtpClient client = new SmtpClient("127.0.0.1");
client.Send(mail);
}
}
private void WriteToLog(string content)
{
StreamWriter sw = new StreamWriter(@"D:\Emailer\log.txt", false);
sw.WriteLine(content);
sw.Close();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.