Hi
I have text files I want to copy the text to MS outlook express. Assist me in writing the code for it
Kritika
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 10:35 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 8:28 PM EDT
Instead of copying data to outlook and then send it, you write code in your application for sending mail by attaching the files like this
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 8:50 PM EDT
What you are saying is Ok. But attached files will not be opened on the receivers machine it has to be as the body of the email. This is the requirement.
Regards
kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 8:53 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 8:55 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 8:59 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 9:02 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 9:12 PM EDT
StringBuilder sb=new StringBuilder();
");
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 9:21 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 9:25 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 9:26 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 9:32 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 9:42 PM EDT
private void button6_Click(object sender, EventArgs e)
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("[email protected]", "Kritika");
mailMessage.To.Add("[email protected]");
mailMessage.Subject = "Test Subject";
mailMessage.IsBodyHtml = true;
string path = @"D:\Files";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.GetFiles("*").OrderByDescending(s => s.LastWriteTime).ToList();
StringBuilder sb = new StringBuilder();
foreach (var fileInfo in files)
{
var filePath = fileInfo.FullName;
using (var textFile = File.OpenText(filePath))
{
sb.Append(textFile.ReadToEnd() + "
");
}
}
mailMessage.Body = sb.ToString();
SmtpClient mailbox = new SmtpClient("ns.tataidc.co.in");
mailbox.Send(mailMessage);
}
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 9:45 PM EDT
service not available, Closing transmission channel
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 9:47 PM EDT
mailbox.Credentials = new NetworkCredential(id, password);
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 9:54 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 9:55 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 10:12 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 10:17 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 11:13 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 11:37 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 12, 2013, 11:47 PM EDT
http://msdn.microsoft.com/en-us/library/cc668191
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Inspectors inspectors;
inspectors = this.Application.Inspectors;
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
mailItem.Subject = "This text was added by using code";
mailItem.To = "[email protected]";
System.IO.StreamReader r = new System.IO.StreamReader("D:/Files/");
string body = r.ReadToEnd();
mailItem.Body = body;
}
}
The code given above is working. It will open outlook exp when I click on New Email , To, Subject and body will showing the proper text. But I do not know how to use the add-ins with user controls like buttons. As you know that I need that when I click a button email will be send.
Guide me
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 12:24 AM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 12:54 AM EDT
mailbox.Send(mailMessage);
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 1:00 AM EDT
mailbox.Send(mailMessage);
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 2:33 AM EDT
");
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 8:54 PM EDT
I tried but its not working . Same exception SERVICE NOT AVAILABLE ,CLOSING CHANNEL
Help in resolving the exception..
Regards
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 8:55 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 8:56 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 9:01 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 9:03 PM EDT
yes i want to use my gmail account.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 9:04 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 9:07 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 9:12 PM EDT
");
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 9:21 PM EDT
smtp server requires a secure connection or the client was not authenticated
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 9:22 PM EDT
mailbox.EnableSsl = true;
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 9:27 PM EDT
Its working now but Can this code send the files one by one to the specified person???
Regards
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 9:30 PM EDT
");
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 9:40 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 9:55 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 9:58 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 10:55 PM EDT
It it possible to search a specific file from multiple directories sort it and then send as email.
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 11:10 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 11:20 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 11:25 PM EDT
Can it be possible that to search for specific file name in different directories with this code.
Thanks
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 11:36 PM EDT
dinfo.GetFiles("test*") like this
it will get files start with test
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 13, 2013, 11:49 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 14, 2013, 12:06 AM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 14, 2013, 12:24 AM EDT
I have dir test inside their is another dir test2 ,test3 and so on so I want to search the file in all the dir and then send the email.
Hope you understand my question
Thanks
Kritika
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:29 PM EDT
Again I have some new queries........
As my program is working properly but I want to sort the files according to date and time mentioned in the very first line of the files.
If possible then guide me completing the project.
I hereby attach sample files for your reference
Regards
Kritika