.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Images and Details through Email to that user

Posted By: kavitha     Posted Date: December 01, 2010    Points:2   Category :ASP.Net
hi friends,

All Images and Details from database are displayed in gridview / datalist.

I need,

if i click that particular row (send button in gridview / datalist) the Images and Details through Email to that particular user.(email Id is retreived from database).

Database:

create table reg(Date DateTime,rid varchar(200),NAME varchar(200),Email varchar(200),imgData image,imgType varchar(200),imgLength bigint,sid numeric identity)

please give in detail.

thanks in advance.

Responses
Author: krishana singh             
Posted Date: December 07, 2010     Points: 5   

http://www.codeproject.com/KB/aspnet/SivaEMailSample.aspx




Author: krishana singh             
Posted Date: December 07, 2010     Points: 5   

<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="LblDate" runat="server" Text='<%#Eval("date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="rid">
<ItemTemplate>
<asp:Label ID="LblRid" runat="server" Text='<%#Eval("rid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name">
<ItemTemplate>
<asp:Label ID="LblName" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="E-Mail">
<ItemTemplate>
<asp:Label ID="LblEmail" runat="server" Text='<%#Eval("email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Send Mail">
<ItemTemplate>
<asp:Button ID="BtnSendMail" runat="server" Text="Click"
onclick="BtnSendMail_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>


code behind.

SqlConnection con;
DataSet ds;
SqlDataAdapter sqlda;

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ToString());
ds = new DataSet();
sqlda = new SqlDataAdapter("SELECT * FROM reg", con);
sqlda.Fill(ds, "reg");
GridView1.DataSource = ds;
GridView1.DataBind();
}
}

protected void BtnSendMail_Click(object sender, EventArgs e)
{
Button cb = sender as Button;
GridViewRow grow = (GridViewRow)cb.NamingContainer;
string date = ((Label)grow.FindControl("LblDate")).Text;
string rid = ((Label)grow.FindControl("LblRid")).Text;
string name = ((Label)grow.FindControl("LblName")).Text;
string email = ((Label)grow.FindControl("LblEmail")).Text;

string body = "Date: " + date + "<br /><br />rid: " + rid + "<br /><br />Name: " + name + "<br />Add other contents>";
string subject = "Automated Mail";
string result = SendMail("YourName", subject, body, email);
Response.Write(result);
}

public string SendMail(string DisplayName, string Subject, string Body, string To)
{
int ClientPort;
string SenderEmailId, SenderPassword, SenderSmtpAddress;
try
{
// Adding Sender Information
ClientPort = 25;
SenderSmtpAddress = "smtp.domain.com"; // Change the domain name
SenderEmailId = "youremailid@domain.com"; // Change the Sender Email ID
SenderPassword = "yourpassword"; // Change the Sender Password

// Building the Message
MailMessage msg = new MailMessage();
msg.To.Add(To);
msg.From = new MailAddress(SenderEmailId, DisplayName, System.Text.Encoding.UTF8);
msg.Subject = Subject;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = Body;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;

// Adding the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(SenderEmailId, SenderPassword);
client.Port = ClientPort; //25 or use 587 or 465
client.Host = SenderSmtpAddress;
client.EnableSsl = true;
client.Send(msg);
}
catch (SmtpException ex)
{
return ("Error: " + ex.Message);
}
return "Mail Sent Successfully";
}

Author: kavitha             
Posted Date: December 07, 2010     Points: 5   

thanks for your response,

but, also send details with Image(user Image) from database(not from the Image folder).

how to create it.

please give in detail.

thanks.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend