none
Process data of datagridview automatically to send mails RRS feed

  • Question

  • i am working on an window application to  send mail automatically.(Birthday Wishes )

    For this i am fetching data from excel sheet to data gridview.

    Now i want that a mail is send to each person whose data is fetch from the Excel Sheet. automatically

    I am not using SMTP i am using OUTLOOK to send mails

    like as below :

     private void sendbutton_Click(object sender, EventArgs e)
           
    {

               
                    
    Outlook.Application oApp = new Outlook.Application();
                    
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                     oMsg
    .HTMLBody = "Hello,";
                    
    String sDisplayName = "MyAttachment";
                    
    int iPosition = (int)oMsg.Body.Length + 1;
                    
    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                    
    Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\Users\\Desktop\\maildemo.txt", iAttachType, iPosition, sDisplayName);
                     oMsg
    .Subject = "Your Subject will go here.";
                    
    Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                    
    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(abcd@gmail.com);
                     oRecip
    .Resolve();
                     oMsg
    .Send();

                    oRecip
    = null;

                    oRecips
    = null;

                    oMsg
    = null;

                    oApp
    = null;

                   
    MessageBox.Show("Mail Sent.. Successfully !!");
    }

    • Edited by Sumit Choudhary Thursday, September 13, 2012 5:06 AM
    • Moved by Chester Hong Friday, September 14, 2012 8:28 AM Outlook question (From:Windows Forms Data Controls and Databinding)
    Thursday, September 13, 2012 5:03 AM

Answers

  • What is your question?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, September 14, 2012 2:36 PM
  • Do you have a specific question?
     
    I see that you're not supplying the recipient address as a string, which is required in the Add() method.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Sumit Choudhary" <=?utf-8?B?U3VtaXQgQ2hvdWRoYXJ5?=> wrote in message news:7cc6dc2c-658e-454e-bb08-63ab8d66ad04...

    i am working on an window application to  send mail automatically.(Birthday Wishes )

    For this i am fetching data from excel sheet to data gridview.

    Now i want that a mail is send to each person whose data is fetch from the Excel Sheet. automatically

    I am not using SMTP i am using OUTLOOK to send mails

    like as below :

     private void sendbutton_Click(object sender, EventArgs e)
           
    {

               
                    
    Outlook.Application oApp = new Outlook.Application();
                    
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                     oMsg
    .HTMLBody = "Hello,";
                    
    String sDisplayName = "MyAttachment";
                    
    int iPosition = (int)oMsg.Body.Length + 1;
                    
    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                    
    Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\Users\\Desktop\\maildemo.txt", iAttachType, iPosition, sDisplayName);
                     oMsg
    .Subject = "Your Subject will go here.";
                    
    Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                    
    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(abcd@gmail.com);
                     oRecip
    .Resolve();
                     oMsg
    .Send();

                    oRecip
    = null;

                    oRecips
    = null;

                    oMsg
    = null;

                    oApp
    = null;

                   
    MessageBox.Show("Mail Sent.. Successfully !!");
    }


    Ken Slovak MVP - Outlook
    Friday, September 14, 2012 2:43 PM
    Moderator

All replies

  • And what has datagridview to do here?

    In any case, you get all the names and other data of users, then do a loop (for or foreach) through all of them, and use the code you have in your 1st post. If you have an account at gmail, you can google for a solution to send emails by gmail`s accout - very simple and efficient).

    bye


    Mitja

    • Proposed as answer by Elegentin Xie Friday, September 14, 2012 8:07 AM
    Thursday, September 13, 2012 7:30 AM
  • Hi Sumit,

    I'll move the thread to Outlook for Developers forum because it is more related to Outlook development question.

    Thanks for your understanding.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 14, 2012 8:28 AM
  • What is your question?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, September 14, 2012 2:36 PM
  • Do you have a specific question?
     
    I see that you're not supplying the recipient address as a string, which is required in the Add() method.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Sumit Choudhary" <=?utf-8?B?U3VtaXQgQ2hvdWRoYXJ5?=> wrote in message news:7cc6dc2c-658e-454e-bb08-63ab8d66ad04...

    i am working on an window application to  send mail automatically.(Birthday Wishes )

    For this i am fetching data from excel sheet to data gridview.

    Now i want that a mail is send to each person whose data is fetch from the Excel Sheet. automatically

    I am not using SMTP i am using OUTLOOK to send mails

    like as below :

     private void sendbutton_Click(object sender, EventArgs e)
           
    {

               
                    
    Outlook.Application oApp = new Outlook.Application();
                    
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                     oMsg
    .HTMLBody = "Hello,";
                    
    String sDisplayName = "MyAttachment";
                    
    int iPosition = (int)oMsg.Body.Length + 1;
                    
    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                    
    Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\Users\\Desktop\\maildemo.txt", iAttachType, iPosition, sDisplayName);
                     oMsg
    .Subject = "Your Subject will go here.";
                    
    Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                    
    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(abcd@gmail.com);
                     oRecip
    .Resolve();
                     oMsg
    .Send();

                    oRecip
    = null;

                    oRecips
    = null;

                    oMsg
    = null;

                    oApp
    = null;

                   
    MessageBox.Show("Mail Sent.. Successfully !!");
    }


    Ken Slovak MVP - Outlook
    Friday, September 14, 2012 2:43 PM
    Moderator