Hi
I want to read some text from a file and make it as subject for the email. Please let me know how to do it.
Kritika
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.
Iftikar HussainPosted Aug 22, 2013, 6:02 AM
Regards,
Iftikar
Iftikar HussainPosted Aug 22, 2013, 6:09 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 6:04 AM
Thanks a lot
Kritika
kritika RanaPosted Aug 22, 2013, 5:55 AM
Iftikar HussainPosted Aug 22, 2013, 5:49 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 5:38 AM
{
string path = @"D:\Test";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.EnumerateFiles("R66*", SearchOption.AllDirectories).OrderBy(s => s.LastWriteTime);
//string path = @"D:\vikas";
//DirectoryInfo dinfo = new DirectoryInfo(path);
// var file = dinfo.GetFiles("R66*").OrderBy(s => s.LastWriteTime).ToList();
StringBuilder sb = new StringBuilder();
try
{
foreach (var fileInfo in files)
{
var filePath = fileInfo.FullName;
using (var textFile = File.OpenText(filePath))
{
string subject = "";
string line;
while ((line = textFile.ReadLine()) != null)
{
if (line.Contains("49101"))
{
subject = GetSubject(line);
break;
}
}
SendMail1(textFile.ReadToEnd(),subject);
}
}
MessageBox.Show("Email Send Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private string GetSubject(string fileContent)
{
var tempArray = fileContent.Split(' ');
var subject = tempArray[1];
return subject;
}
private void SendMail1(string fileContent,string sub)
{
MailMessage mailMessage = new MailMessage();
// mailMessage.From = new MailAddress("[email protected]", "Kritika");
mailMessage.From = new MailAddress("[email protected]", "kritika");
mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
mailMessage.Subject = "Spicejet-APU Shutdown Report " +sub ;
mailMessage.IsBodyHtml = true;
mailMessage.Body = fileContent + "
";
using (SmtpClient mailbox = new SmtpClient("smtp.gmail.com", 587))
{
mailbox.Credentials = new NetworkCredential("[email protected]", "paswd");
// mailbox.Credentials = new NetworkCredential("[email protected]", "abc");
mailbox.EnableSsl = true;
mailbox.Send(mailMessage);
}
}
Iftikar HussainPosted Aug 22, 2013, 5:34 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 5:32 AM
03960 09201 08664
Iftikar HussainPosted Aug 22, 2013, 3:38 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 2:54 AM
Iftikar HussainPosted Aug 22, 2013, 2:09 AM
kritika RanaPosted Aug 22, 2013, 2:08 AM
Iftikar HussainPosted Aug 22, 2013, 2:05 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 2:02 AM
{
MailMessage mailMessage = new MailMessage();
// mailMessage.From = new MailAddress("[email protected]", "Kritika");
mailMessage.From = new MailAddress("[email protected]", "kritika");
mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
mailMessage.Subject = "Spicejet-APU Shutdown Report VT- " +subject;
mailMessage.IsBodyHtml = true;
mailMessage.Body = fileContent + "
";
using (SmtpClient mailbox = new SmtpClient("smtp.gmail.com", 587))
{
mailbox.Credentials = new NetworkCredential("[email protected]", "pawd");
// mailbox.Credentials = new NetworkCredential("[email protected]", "abc");
mailbox.EnableSsl = true;
mailbox.Send(mailMessage);
}
}
Iftikar HussainPosted Aug 22, 2013, 1:57 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 1:53 AM
Iftikar HussainPosted Aug 22, 2013, 1:38 AM
SendMail1(textFile.ReadToEnd(),subject );
kritika RanaPosted Aug 22, 2013, 1:36 AM
kritika RanaPosted Aug 22, 2013, 1:34 AM
Iftikar HussainPosted Aug 22, 2013, 1:32 AM
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 1:29 AM
My code is as
private void button1_Click_1(object sender, EventArgs e)
{
string path = @"D:\Test";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.EnumerateFiles("R66*", SearchOption.AllDirectories);
//string path = @"D:\vikas";
//DirectoryInfo dinfo = new DirectoryInfo(path);
var file = dinfo.GetFiles("R66*").OrderBy(s => s.LastWriteTime).ToList();
StringBuilder sb = new StringBuilder();
try
{
foreach (var fileInfo in files)
{
var filePath = fileInfo.FullName;
using (var textFile = File.OpenText(filePath))
{
string subject = "";
string line;
while ((line = textFile.ReadLine()) != null)
{
if (line.Contains("49101"))
{
subject = GetSubject(line);
break;
}
}
//SendMail(textFile.ReadToEnd());
SendMail1(textFile.ReadToEnd(),subject );
}
}
MessageBox.Show("Email Send Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Mail Not Send Check for error", ex.ToString());
}
}
private string GetSubject(string fileContent)
{
var tempArray = fileContent . Split(' ');
var subject = tempArray[1];
return subject;
}
Iftikar HussainPosted Aug 22, 2013, 1:24 AM
string subject="";
string line;
break;
SendMail(textFile.ReadToEnd(),subject );
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 1:17 AM
Iftikar HussainPosted Aug 22, 2013, 12:57 AM
string subject="";
string line;
break;
private string GetSubject(string fileContent)
{
var tempArray = fileContent.Split(' ');
var subject = tempArray[1];
return subject;
kritika RanaPosted Aug 22, 2013, 12:52 AM
while ((line = file.ReadLine()) != null)
{
if (line.Contains("49101"))
{
subject = GetSubject(line);
break;
}
}
private string GetSubject(string fileContent)
{
var tempArray = temp.Split(' ');
var subject = tempArray[1];
return subject;
}
Iftikar HussainPosted Aug 22, 2013, 12:33 AM
string subject="";
string line;
break;
private string GetSubject(string fileContent)
{
var tempArray = temp.Split(' ');
var subject = tempArray[1];
return subject;
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 12:25 AM
Iftikar HussainPosted Aug 22, 2013, 12:19 AM
49101 VT-SGH B737-800 130805 XXXXXX VAAH. VIDP. 0132 ROJ807
Regards,
Iftikar
kritika RanaPosted Aug 22, 2013, 12:15 AM
Iftikar HussainPosted Aug 22, 2013, 12:04 AM
Please share the file format.
Regards,
Iftikar