Click here to Skip to main content
15,887,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I can add one textbox link but I need to add 3 or more to the subject line.

Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
           Microsoft.Office.Interop.Outlook.MailItem mailItem = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
           //  mailItem.Subject = "This is a Automatic Email";  // Hard code Subject line
           mailItem.Subject = txt_CHKR.Text; txt_PN.Text;  // Need Help here
           mailItem.To = "Email.Address.Here@gmail.com";


What I have tried:

error is on this line

//Add Subject
                 oMailItem.Subject = mailItem.Subject = txt_CHKR.Text; txt_PN.Text; 
Posted
Updated 4-Jun-21 16:48pm
Comments
Dave Kreskowiak 4-Jun-21 19:39pm    
Hint: Why are there two = symbols in that line? There should only be one.
Member 12349103 4-Jun-21 20:06pm    
Dave
typo I tried mailItem.Subject = txt_CHKR.Text; txt_PN.Text; // Need Help here

1 solution

Subject for a mail item is a property. This means that you can (typically) query it or assign a single value to it. So if you want to assign multiple values which originate from different text boxes, you first need to concatenate them, one way or another, and then do the assignment.

For example, you can try the following
C#
mailItem.Subject = $"{txt_CHKR.Text} {txt_PN.Text}";

Few links you may find useful:
- Properties - C# Programming Guide | Microsoft Docs[^]
- $ - string interpolation - C# reference | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 12349103 5-Jun-21 10:32am    
works great
Member 12349103 7-Jun-21 16:50pm    
wendelius

how can I save the subject line as the Image name?
Wendelius 7-Jun-21 23:17pm    
Not sure what you mean, but I suggest opening a new question to Q&A. Just remember to explain your goal and the issue you're facing.

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