Send Mail and how to Save in PDF


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
#form1
{
height: 591px;
}
</style>
</head>
<body background="Leonoralabs.jpg"<marquee direction="up" width="238" height="100%"
scrollamount="15" onmouseout="javascript:fast(this);"
onmouseover="javascript:slow(this);">welcome to Leonora Labs</marquee>>

<form id="form1" runat="server" method="post">
<div><h2 id="hh" align="center">welcome to Leonora Labs</h2>

<p>&nbsp;</p></div>
<div align="center">

&nbsp;</div>
<p>
<asp:TextBox ID="TextBox2" runat="server"

style="top: 191px; left: 151px; position: absolute; height: 22px; width: 502px"
BackColor="#E6FFFF"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label1" runat="server" Text="From G-Email Only" Font-Bold="True"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
ForeColor="#0000CC" style="text-align: right"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"

style="top: 142px; left: 154px; position: absolute; height: 22px; width: 501px; bottom: 343px; text-align: center;"
BackColor="#E6FFFF" ontextchanged="TextBox1_TextChanged"></asp:TextBox>


</p>
<p>
<asp:Label ID="Label2" runat="server" Text="To" Font-Bold="True"
ForeColor="#0000CC"></asp:Label>
</p>

<p>
<asp:TextBox ID="TextBox4" runat="server"

style="top: 299px; left: 166px; position: absolute; height: 128px; width: 502px"
BackColor="#E6FFFF" TextMode="MultiLine"></asp:TextBox>
</p>
<asp:TextBox ID="TextBox3" runat="server"

style="top: 236px; left: 148px; position: absolute; height: 22px; width: 502px"
BackColor="#E6FFFF"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Subject" Font-Bold="True"
ForeColor="#0000CC"></asp:Label>
<br />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Body" Font-Bold="True"
ForeColor="#0000CC"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="top: 590px; left: 376px; position: absolute; height: 26px; width: 56px; right: 729px"
Text="Send" Font-Bold="True" ForeColor="#0000CC" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
style="top: 592px; left: 463px; position: absolute; height: 26px; width: 56px"
Text="Save" Font-Bold="True" ForeColor="#0000CC" />
<asp:TextBox ID="TextBox5" runat="server" BackColor="#E6FFFF"
ontextchanged="TextBox5_TextChanged"

style="top: 459px; left: 167px; position: absolute; height: 124px; width: 496px"></asp:TextBox>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Massage seen after SAVE"
Font-Bold="True" ForeColor="#0000CC"></asp:Label>
</form>
</body>
</html>

<script type="text/javascript">

var k = 0;

function blinker() {

k++;

var a = document.getElementById("hh");

if (k % 2 == 0) {

a.style.visibility = "hidden";

}

else {

a.style.visibility = "visible";

}

//reset the value of k so that it does not keep

// on incrementing

if (k == 30) {

k = 0;

}

window.setTimeout("blinker()", 500);

}

blinker();

</script>

//////////
Button Click Events
////////////

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox5.Text = "";
if (!IsPostBack)
{
TextBox4_Load();
}
}

private void TextBox4_Load()
{
//throw new NotImplementedException();
if (File.Exists(Server.MapPath("Tusar.pdf")))
{
//StreamReader StreamReader1 = new StreamReader(Server.MapPath("test.txt"));
StreamReader StreamReader1 = new StreamReader(Server.MapPath("Tusar.pdf"));
TextBox4.Text = StreamReader1.ReadToEnd();
StreamReader1.Close();

}
else
{
TextBox4.Text = "New file.";
}
}
void TextBox5_Load()
{
if (File.Exists(Server.MapPath("Tusar.pdf")))
{
//StreamReader StreamReader1 = new StreamReader(Server.MapPath("tes.txt"));
StreamReader StreamReader1 = new StreamReader(Server.MapPath("Tusar.pdf"));
TextBox5.Text = StreamReader1.ReadToEnd();
StreamReader1.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage(TextBox1.Text, TextBox2.Text,TextBox3.Text, "");
MyMailMessage.IsBodyHtml = false;
MyMailMessage.Body = TextBox4.Text;
//provide Authentication Details need to be ed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(TextBox1.Text, "word");//Sender word

//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

//Enable SSL

mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);
}

protected void Button2_Click(object sender, EventArgs e)
{
StreamWriter StreamWriter1 = new StreamWriter(Server.MapPath("Tusar.pdf"));
StreamWriter1.WriteLine(TextBox4.Text);
StreamWriter1.WriteLine("Line1.\r\nLine2.");
StreamWriter1.Close();
TextBox5_Load();
}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{

}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

}
}


Similar Articles