I have created one application where i am using two form - 1) planform and 2) statusform
and 3rd form i have created to send mail, I have done coding -
public void sendmailbtn_Click(object sender, EventArgs e)
{
planform obj = new planform();
statusform obj1 = new statusform();
MailMessage mail = new MailMessage();
mail.To.Add(tobox.Text);
mail.From = new MailAddress(frombox.Text);
mail.Subject = DateTime.Now.ToShortDateString() + "-Planned Task Register (PTR)"; // subject
mail.Body = bodyboxarea.Text;
mail.CC.Add(new MailAddress(ccbox.Text));
mail.IsBodyHtml = true;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(filebox.Text);
mail.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("gmailid", "password");
smtp.EnableSsl = true;
smtp.Send(mail);
this.Hide();
MessageBox.Show("Mail sent");
}
it is working fine, currently "subject" will be same for both plan and status but i want subject line should change when i ll click on status form
it should be like -
mail.Subject = DateTime.Now.ToShortDateString() + "-StatusTask Register (PTR)"; // subject
for this i have created global variable but still i did'nt get...
how i ll do that??
Iftikar HussainPosted Aug 13, 2013, 1:05 AM
You need to create a class as static with one property like below
When you are going from your form 1 (planform) to form3 then
set Global.GlobalVariable="Planned Task Register (PTR)";
When you are going from your form 2 (status) to form3 then
set Global.GlobalVariable="StatusTask Register (PTR)";
in your form3
mail.Subject = DateTime.Now.ToShortDateString() + "-" + Global.GlobalVariable; // subject
Regards,
Iftikar
Iftikar HussainPosted Aug 13, 2013, 1:26 AM
Regards,
Iftikar
rachayita jaiswalPosted Aug 13, 2013, 1:23 AM
Thanks again.