Diễn đàn lập trình viên .NET
Trang chủ       Thành viên    Lịch    Ai đang online
Chào mừng khách ( Đăng nhập | Đăng ký )
        


««12

Gửi Email động trong ASP.NET Nới rộng / Co lại
Tác giả
Tin nhắn
Đả gửi Sunday, July 11, 2010 6:31 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Nhóm: Forum Members
Lần đăng nhập cuối: Sunday, July 11, 2010 6:31 PM
Đả gửi: 1, Thăm: 2
Mình xin chia sẽ Code send mail với bạn nhé !

Trong source code nà:

<table cellpadding="0" cellspacing="0" style="width: 650px">

<tr>

<td style="width: 3px">

&nbsp;</td>

<td style="width: 130px; padding-top: 3px; padding-bottom: 3px;">

<asp:Label ID="Label11" runat="server" Text="Họ v… tˆn *"

style="font-family: Arial, Helvetica, sans-serif" Width="130px"></asp:Label>

</td>

<td style="width: 3px">

&nbsp;</td>

<td style="width: 260px">

<asp:TextBox ID="txthoten" runat="server" Width="250px" BorderColor="#7DBEFF"

BorderWidth="1px"></asp:TextBox>

</td>

<td style="width: 3px">

&nbsp;</td>

<td style="width: 251px">

<asp:Label ID="Label19" runat="server" Text="Nội dung liˆn hệ *"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td style="width: 3px">

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td style="padding-top: 3px; padding-bottom: 3px">

<asp:Label ID="Label12" runat="server" Text="Chức danh"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txtchucdanh" runat="server" Width="250px"

BorderColor="#7DBEFF" BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td rowspan="7" style="width: 251px" valign="top">

<asp:TextBox ID="txtnoidung" runat="server" Height="155px" TextMode="MultiLine"

Width="251px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td style="padding-top: 3px; padding-bottom: 3px">

<asp:Label ID="Label13" runat="server" Text="Tˆn c“ng ty"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txttencongty" runat="server" Width="250px"

BorderColor="#7DBEFF" BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td style="padding-top: 3px; padding-bottom: 3px">

<asp:Label ID="Label14" runat="server" Text="Địa chỉ *"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txtdiachi" runat="server" Width="250px" BorderColor="#7DBEFF"

BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td style="padding-top: 3px; padding-bottom: 3px">

<asp:Label ID="Label15" runat="server" Text="Điện thoại "

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txtdienthoai" runat="server" Width="250px"

BorderColor="#7DBEFF" BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td>

<asp:Label ID="Label16" runat="server" Text="Fax"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txtfax" runat="server" Width="250px" BorderColor="#7DBEFF"

BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td style="padding-top: 3px; padding-bottom: 3px">

<asp:Label ID="Label17" runat="server" Text="Email*"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txtemail" runat="server" Width="250px" BorderColor="#7DBEFF"

BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td style="padding-top: 3px; padding-bottom: 3px">

<asp:Label ID="Label18" runat="server" Text="Chủ đề"

style="font-family: Arial, Helvetica, sans-serif"></asp:Label>

</td>

<td>

&nbsp;</td>

<td>

<asp:TextBox ID="txtchude" runat="server" Width="250px" BorderColor="#7DBEFF"

BorderWidth="1px"></asp:TextBox>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td style="height: 30px; width: 211px;" valign="bottom">

<table cellpadding="0" cellspacing="0" style="width: 211px">

<tr>

<td style="width: 105px; text-align: center;">

<asp:Button ID="btngui" runat="server" BorderColor="#CCFFCC"

style="color: #FFFFFF; background-color: #972015" Text="Gửi" Width="90px"

onclick="btngui_Click" />

</td>

<td style="width: 105px; text-align: center;">

<asp:Button ID="btnlamlai" runat="server" BorderColor="#CCFFCC"

style="color: #FFFFFF; background-color: #972015" Text="L…m lại"

Width="90px" CausesValidation="False" />

</td>

</tr>

</table>

</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

</table>

//==========Và đây là trong code Behind===========

Khai báo:

using System;

using System.Collections;

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.Net.Mail;

using System.Timers;

using System.Web.Mail;

 

//Viết trong sự kiện n£t gửi mail.

protected void btngui_Click(object sender, EventArgs e)

{

try

{

string mailTo = "xulymail@gmail.com";

string subject = txtchude.Text;

string content = "Họ tˆn " + txthoten.Text + "\r>"+"Email:"+txtemail.Text

+ ". Địa chỉ " + txtdiachi.Text + "\r>" + ". Điện thoại " + txtdienthoai.Text

+ "\r+ ". Fax " + txtfax.Text + \r>" + ". Nội dung " + txtnoidung.Text;

bSendEmail(mailTo, subject, content);

Response.Write(@"<script language='javascript'>alert('Gửi yeu cau thanh cong !')</script>");

}

catch (Exception)

{

Response.Write(@"<script language='javascript'>alert('Đã phat sinh loi, vui long thu lai!')</script>");

}

}

//h…m gửi mail.

public bool bSendEmail(string sTo, string sSubject, string sContent)

{

bool bFlag = false;

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

msg.From = new MailAddress("chinhtam@chinhtam.vn");

msg.To.Add(sTo); //from argument

msg.Subject = sSubject; //from argument

//msg.IsBodyHtml = isHTML; //from argument

msg.Body = sContent; //from argument

SmtpClient smtp = new SmtpClient("mail.chinhtam.vn");

smtp.Credentials = new System.Net.NetworkCredential("EmailTrongHost@chinhtam.vn", "passcuamail");

smtp.Send(msg); //send email out

msg.Dispose(); //get rid of the object

return bFlag;

}

//====Xong rồi đó bạn.

Nếu có gì không được thì buzz qua yahoo cho mình nhé: dangquest   or Email: dangquests@gmail.com.

 

 



Thiên niên thiết thọ khai hoa dị, Nhất thất nhân thân vạn kiếp niên.
Bài viết thứ #2096
« Chủ đề trước | Chủ đề kế »

««12

Đang đọc chủ đề này Nới rộng / Co lại
Thành viên đang họat động: 0 (0 Các khách, 0 thành viên, 0 thành viên ẩn danh)
Không có thành viên nào hiện tại xem chủ đề này.
Diễn đàn Mod: Admin, Bill_Gates

All times are GMT +7:00, Bây giờ là 3:48pm

Powered by InstantForum.NET v4.1.4 © 2010
Sự thực thi: 0.219. 11 queries. Vô hiện hoá chức năng nén.
Tin học bình dân Free download ebook, wordpress theme. Seo tips, domain hosting review. And much more...