Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using SQLite database and outlook = Microsoft.Office.Interop.Outlook; to send email to user.
How can I get a textbox data into the subject line from my database?


private void txt_Mail_Bot_Click(object sender, EventArgs e)
         {
             try
             {
                 List<string> lstAllRecipients = new List<string>();
                 //Below is hardcoded - can be replaced with db data
                 lstAllRecipients.Add("email@.COM");
                 //  lstAllRecipients.Add("email@.COM ");

                 outlook.Application outlookApp = new outlook.Application();
                 outlook._MailItem oMailItem = (outlook._MailItem)outlookApp.CreateItem(outlook.OlItemType.olMailItem);
                 outlook.Inspector oInspector = oMailItem.GetInspector;
                 // Thread.Sleep(10000);

                 // Recipient
                 outlook.Recipients oRecips = (outlook.Recipients)oMailItem.Recipients;
                 foreach (String recipient in lstAllRecipients)
                 {
                     outlook.Recipient oRecip = (outlook.Recipient)oRecips.Add(recipient);
                     oRecip.Resolve();
                 }

                 //Add CC
                 outlook.Recipient oCCRecip = oRecips.Add("DifferntEmail@.com");
                 oCCRecip.Type = (int)outlook.OlMailRecipientType.olCC;
                 oCCRecip.Resolve();

                 //Add Subject
                 oMailItem.Subject = " Issue here Need to get info from Data Base Here";

                 // body, bcc etc...

                 oMailItem.Body = "This is Body Info no problem here.";

                 // body, bcc etc...

                 //Display the mailbox
                 oMailItem.Display(true);
             }
             catch (Exception objEx)
             {
                 //   Response.Write(objEx.ToString());

             }
         }
     }
 }


What I have tried:

Html code no avail I cant find a info to lead me in the correct direction.
Posted
Updated 4-May-21 21:56pm

1 solution

What is wrong with:
C#
oMailItem.Subject = textboxSubject.Text;
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900