Total Pageviews

18 April 2012

How to send Online mail in asp.net


About.aspx=>
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
   
    <table class="style5">
    <tr>
        <td class="style7">
            &nbsp;</td>
        <td class="style8">
            <asp:Label ID="dsl" Runat="server" ForeColor="#CC0000"></asp:Label>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style7">
            <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To&nbsp;</strong></td>
        <td class="style8">
            <asp:TextBox ID="t6" runat="server" Width="175px"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style7">
            <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; From</strong></td>
        <td class="style8">
            <asp:TextBox ID="t7" runat="server" Height="23px" Width="176px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="style7">
            <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Subject</strong></td>
        <td class="style8">
            <asp:TextBox ID="t8" runat="server" Height="20px" Width="176px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="style7">
            <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Body</strong></td>
        <td class="style8">
            <asp:TextBox ID="t9" runat="server" Height="88px" TextMode="MultiLine"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="style5" colspan="2">
            <div>
                <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Attachment:</strong>&nbsp;<asp:FileUpload
                    ID="fp0" runat="server" />
                <br />
            </div>
        </td>
    </tr>
    <tr>
        <td align="center" colspan="2">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button2" runat="server" BorderStyle="None" Font-Bold="True"
                Font-Italic="True" ForeColor="#990033" onclick="Button2_Click"
                Text="Send Email" />
        </td>
    </tr>
</table>
   
</asp:Content>
About.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.IO;
public partial class About : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        String s = t6.Text;
        String[] toId = s.Split(',');
        MailMessage mail = new MailMessage();
        for (int i = 0; i <= toId.Length - 1; i++)
        {
            mail.To.Add(toId[i].ToString());
        }
        mail.To.Add(new MailAddress(t6.Text));
        mail.From = new MailAddress("ownEmailid");
        mail.IsBodyHtml = true;
        mail.Subject = t8.Text;
        mail.Body = t9.Text;
        SmtpClient smtp1 = new SmtpClient();
        smtp1.Host = "smtp.gmail.com";
        smtp1.Port = 587;
        smtp1.UseDefaultCredentials = false;
        smtp1.Credentials = new NetworkCredential("Own Emailid", "pass");
        smtp1.EnableSsl = true;
        byte[] data = new byte[102400];
        //System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
        //Attachment attach = new Attachment(stream, "Attachment file name");
        //mail.Attachments.Add(attach);
        if (fp0.HasFile)
   {
      mail.Attachments.Add(new Attachment(fp0.PostedFile.InputStream, fp0.FileName));
       }
        smtp1.Send(mail);
        t6.Text = "";
        t8.Text = "";
        t9.Text = "";
        dsl.Visible = true;
        dsl.Text = "Message sent.";
    }
}

How to upload Large file in Asp.net


How upload Large file in Asp.net programme

To make the above modifications to your application for large file uploads you need to:
1.Open the Solution Explorer, navigate to the application web.config file and open it.
2.Under the <configuration> element locate the <system.web> element. Add it if it does not exist.
3.Under the <system.web> element locate the <httpRuntime> element. Add it if it does not exist.
4.In the <httpRuntime> element locate the maxRequestLength and executionTimeout attributes. If they do not exist, add them and set their values:
Webconfig=>
<configuration>
...
    <system.web>
      <httpRuntime maxRequestLength="102400" executionTimeout="3600" />
      ...
    </system.web>
</configuration>
For IIS7=><system.webserver>
...
<security >
    <requestFiltering>
        <requestLimits maxAllowedContentLength="1024000000" />
    </requestFiltering>
</security>
</system.webserver>•Open the file C:\Windows\System32\inetsrv\config\applicationHost.config and find the line:
<section name="requestFiltering" overrideModeDefault="Deny" />
•Set the overrideModeDefault property to Allow. So now the line should look like:
<section name="requestFiltering" overrideModeDefault="Allow" />

Contact Form

Name

Email *

Message *