Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Sending messages by email and Microsoft Office Communicator 2005

, 2 Jun 2008
Rate this:
Please Sign up or sign in to vote.
Save time sending massive messages.

Introduction

This program tries to make your life easier when you're at work. Every time you want to go on break time, you would have to type emails or add a lot of contacts to a conversation to say: "let's go and have a coffee!" Now, only with a double click, this program does it for you.

Background

The message sender is based on the article: "Automate key sequences for repetitive tasks, reference XML data". With very little changes, you can improve it to reach the objective. So, please read SathishVJ's article before reading this, so you can understand the changes I have done.

Using the code

The application reads from a text file named emails.txt, where you include the emails of the people in your company. You have to list each email in one line without separating them with a comma. The first line is read and it opens a new messenger conversation. Then, the following emails are added into the conversation. Using the SendKeys function, the program takes control of the messenger and writes the message you want to your workmates.

string destinatario = "";

public bool LoadKeySequence() 
{
    ArrayList keySequenceArray = new ArrayList();

    StreamReader sr = new StreamReader(@"emails.txt");
    String line;
    if ((line = sr.ReadLine()) != null) 
    {
        line = line.Trim();
        //Opens new conversation
        keySequenceArray.Add("%(a)s");
        keySequenceArray.Add(line);
        keySequenceArray.Add("{TAB}{TAB}{ENTER}");
        destinatario += line;
        while ((line = sr.ReadLine()) != null)
        {
            destinatario += ",";
            line = line.Trim();
            //Add to conversation
            keySequenceArray.Add("%(a)j");
            keySequenceArray.Add(line);
            keySequenceArray.Add("{TAB}{TAB}{ENTER}");
            //Email receivers list separated by comma
            destinatario = destinatario+ line;
        }
        keySequenceArray.Add("Let's have a break and a coffee");
        keySequenceArray.Add("{ENTER}");
        keySequenceArray.Add("Auto message!!!");
        keySequenceArray.Add("{ENTER}");
        keySequenceArray.Add("{ESC}");
     }

    this.sendKeysSequence = (string[])keySequenceArray.ToArray(typeof(string));
    return true;
}

Now, I'm going to explain how to send the emails:

string asunto = "BREAK TIME";
string body = "Don't answer to this email. Let's meet at the office door!!!!";

private void mandarEmails()
{
    //Write your company SMTP server.
    string servidor = "company.smtp.server";
    string html = "";
    // Write who's sending the email and the receivers of your email 
    MailMessage message = new MailMessage("myemail@domain.eh",destinatario);
    // You can write what ever you want in the email and put your signature
    message.IsBodyHtml = true;
    html += @"<html><head> … ";
        .
        .
        .
    html += @" … </head></html>";
    System.Text.StringBuilder messageBody = new System.Text.StringBuilder();
    messageBody.Append(html);
    message.Body = messageBody.ToString();
    message.BodyEncoding = System.Text.Encoding.UTF8;
    message.Subject= asunto;
    SmtpClient cliente = new SmtpClient(servidor);
    //Add credentials to the server
    cliente.Credentials = CredentialCache.DefaultNetworkCredentials;
    //Here you send the email 
    try 
    {
        cliente.Send(message);
    }
    catch (System.Net.Mail.SmtpException ex)
    {

 
        MessageBox.Show("ERROR!!");
    }
}

In MainForm(), you have to specify the process you want to open, in this case, it is communicator.exe:

System.Diagnostics.Process p= new System.Diagnostics.Process();
p.StartInfo.FileName = @"communicator.exe";
p.Start();

In main():

static void Main()
{
     MainForm brum = new MainForm();
     brum.arranca(); 
}

This is the important part:

private void arranca()
{
    if (!this.LoadKeySequence())
    {
        return;
    }
     //Find process handle 
    if (!this.FindProcess())
    {
        return;
    }
    SetForegroundWindow(this.processWindowHandle);
    SetActiveWindow(this.processWindowHandle);
    mandarEmails();
    if (this.noDataFilesRequiredCheckBox.Checked)
    {
        //call other method 
        for (int i = 0; i< this.repeatCountNumericUpDown.Value; i++)
         { 
            ExecuteKeySequence(null);
        }
    SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
    MessageBox.Show("I have sent everything!!");


    Application.Exit();
    return;
    }
}

Finally, set thse in the MainForm.cs design interface:

  • keySequenceFileTextBox.Text= Path where the file "emails.txt" is.
  • targetAppTitleTextBox.Text= Microsoft Office Communicator

And your program is finished and ready to run!! Have fun with it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mikel A. Rodriguez
Engineer
Spain Spain
I have studied Telecommunication engineering at the Public University of Navarra. Now working in Business Intelligence as an analyst consultant in TIC projects.

Comments and Discussions

 
GeneralDoesn't compile PinmemberDumpsterJuice2-Jun-08 9:27 
GeneralRe: Doesn't compile PinmemberMikel A. Rodriguez3-Jun-08 1:09 
GeneralRe: Doesn't compile PinmemberDumpsterJuice3-Jun-08 1:48 
GeneralRe: Doesn't compile PinmemberMikel A. Rodriguez3-Jun-08 3:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 2 Jun 2008
Article Copyright 2008 by Mikel A. Rodriguez
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid