TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sheikh parvaz
NA
199
108.5k
Sending email to many in databes table
Aug 6 2014 2:21 AM
The below program show me
A recipient must be specified.
Kindly help
public partial class _Default : System.Web.UI.Page
{
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSendEmail_Click(object sender, EventArgs e)
{
if (txtemailfrom.Text == "" || txtsubject.Text == "" || txtbody.Text == "")
{
lblmail.Text = "Please fill all mandatory fields.";
lblmail.Visible = true;
return;
}
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMessage = new MailMessage();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["stringconnect"].ConnectionString);
ArrayList list_emails = new ArrayList();
int i = 0;
string email;
con.Open();
SqlCommand cmd = new SqlCommand("Select EmailId from SendEmailToStudent", con);
SqlDataReader read_Email = cmd.ExecuteReader();
while (read_Email.Read())
{
email = read_Email.GetValue(i).ToString();
list_emails.Add(email); //Add email to a arraylist
i = i + 1 - 1;
}
read_Email.Close();
con.Close(); //Close connection
foreach (string email_to in list_emails)
{
if (fileAttachement.PostedFile != null)
{
HttpPostedFile AttachFile = fileAttachement.PostedFile;
int AttachFileLength = AttachFile.ContentLength;
if (AttachFileLength > 0)
{
// FileName = Path.GetFileName(fileAttachement.PostedFile.FileName);
}
}
MailAddress fromAddress = new MailAddress(txtemailfrom.Text);
mailMessage.From = fromAddress;
mailMessage.Subject = txtsubject.Text;
mailMessage.Body = txtbody.Text;
string Body = "";
Body += '\n' + "From:" + txtemailfrom.Text;
Body += '\n' + "";
Body += '\n' + "Subject:" + txtsubject.Text;
Body += '\n' + "";
Body += '\n' + txtbody.Text;
mailMessage.IsBodyHtml = true;
mailMessage.Body = Body;
SmtpClient smtp = new SmtpClient("SMTP Server");
smtpClient.Send(mailMessage);
lblmail.Visible = true;
lblmail.Text = "Your mail has been sent successfully";
tblemail.Visible = true;
}
txtemailfrom.Text = "";
txtsubject.Text = "";
txtbody.Text = "";
}
}
Reply
Answers (
1
)
i have a login page after entering correct info user go to
adRotator