hii everyone
can
anyone tell me the websites or coding for sending mails from database
when we forgot password or registered into the website in c#
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Praveen VenugopalPosted Sep 1, 2008, 5:12 AM
Hi,
here with i have showed you a simple mail sending program. u can use it to customise your need
In Webconfig file
In .aspx page
From:
To:
Subject:
Attachments:
Body:
In Code Behind:
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.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
Mailsending();
}
public void Mailsending()
{
string strfrom = txtFrom.Text;
string strto = txtto.Text;
string strsubject = txtSubject.Text;
string strbody = txtBody.Text;
MailMessage mail = new MailMessage();
mail.From = new MailAddress (strfrom);
mail.To.Add (new MailAddress (strto));
mail.Subject = strsubject;
mail.Body = strbody;
//MailAttachment attachment = null;
Attachment attachment = null;
try
{
// check to see if there are any attachments or not
if(FileList.Items.Count > 0)
{
foreach(ListItem l in FileList.Items)
{
// Attaches a new attachment contained in the List
Response.Write(l.Text);
attachment = new Attachment(l.Text);
mail.Attachments.Add(attachment);
}
}
//mail.Attachments.Add(attachment);
//Response.Write("Number of attachments are"+mail.Attachments.Count);
SmtpClient objsend = new SmtpClient();
objsend.Host = "your mail server name or id";
objsend.Send(mail);
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(60000);
Mailsending ();
// Cacthes the exception here
}
}
protected void btnAttach_Click(object sender, EventArgs e)
{
// gets the file name with the whole path
string attachedFile = MyFile.PostedFile.FileName;
// Adds the item in the list of attached files
if (attachedFile != "")
{
FileList.Items.Add(attachedFile);
}
}
protected void btnRemoveattachment_Click(object sender, EventArgs e)
{
FileList.Items.Remove(FileList.SelectedItem);
}
}
Cheers