Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i fetch email id through list but after adding it into
mail.To.Add(mails);

it will directly go to catch..
canot convert from 'System.Collection.Generic.List<Model>' to 'string'
give this error...

What I have tried:

<pre> var email =HomeworkReposities.get_studentdetails(classId, divisionId, subjectId);
                       
                           string mails =email.ToString();
                         string SMTP_HOST = "smtp.sendgrid.net";
                        string SMTP_PORT = "587";
                        try
                        {
                            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                            mail.To.Add(mails);
Posted
Comments
littleGreenDude 5-Oct-18 7:35am    
I recommend looking at the example in the following URL:

https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage?view=netframework-4.7.2
Richard MacCutchan 5-Oct-18 8:43am    
You cannot convert a list of items to a string, you must take the items one at a time and concatenate them.
Member 12227707 6-Oct-18 1:37am    
i want to send homework details at a time to all the student through mail....
Richard MacCutchan 6-Oct-18 3:59am    
You create the variable email from HomeworkReposities.get_studentdetails(classId, divisionId, subjectId);. The error message indicates that this returns a System.Collections.Generic.List, which does not have a simple ToString method. You need to go through the list and extract each mail address to add to your mail message.
Member 12227707 6-Oct-18 4:50am    
ok.thank u sir...

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