How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl.http://forums.asp.net/t/1761222.aspx/1?How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Mon, 27 Feb 2012 08:31:44 -050017612224794689http://forums.asp.net/p/1761222/4794689.aspx/1?How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p><span class="hps">Hello</span><span>,</span><br> <br> <span class="hps">I have</span> <span class="hps">created</span> <span class="hps"> a component</span> <span class="hps">for</span> <span class="hps">a website</span> <span class="hps">to send</span> <span class="hps">emails</span> <span class="hps"> to</span> <span class="hps">users</span><span>.</span><br> <br> <span class="hps">This video</span> <span class="hps">has</span> <span class="hps"> really</span> <span class="hps">helped</span> <span class="hps">me with that</span><span>:<a href="http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-reusable-component-for-sending-email-to-a-distribution-list">http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-reusable-component-for-sending-email-to-a-distribution-list</a></span><br> <span class="hps">I</span> <span class="hps">want the</span> <span class="hps">users</span> <span class="hps">to send</span> <span class="hps">emails</span> <span class="hps"> from the website</span> <span class="hps">at</span><span>, say, 6</span> <span class="hps"> registered users</span> <span class="hps">in</span> <span class="hps">a</span> <span class="hps"> database with</span> <span class="hps">the email address</span> <span class="hps"> from a database</span> <span class="hps">are</span> <span class="hps">selected.</span><br> <br> <span class="hps">These</span> <span class="hps">six</span> <span class="hps">must be selected</span> <span class="hps">from a database</span> <span class="hps">with</span> <span class="hps"> multiple users in</span> <span class="hps">the</span> <span class="hps">database that contains a</span> <span class="hps">zip code</span> <span class="hps">is included</span><span>.</span><br> <br> <span class="hps">How</span> <span class="hps">can I</span> <span class="hps">modify</span> <span class="hps">the code</span> <span class="hps">to read</span> <span class="hps"> a</span> <span class="hps">list</span> <span class="hps">of</span> <span class="hps"> recipients</span> <span class="hps">from</span> <span class="hps">a</span> <span class="hps"> data</span> <span class="hps">source and</span> <span class="hps">send an email</span> <span class="hps">message to</span> <span class="hps">a</span> <span class="hps"> few</span> <span class="hps">of the</span> <span class="hps">recipients</span> <span class="hps"> in the</span> <span class="hps">DataSource</span> <span class="hps">Using the</span> <span class="hps">System.Net.Mail</span> <span class="hps">class</span> <span class="hps"> UserWebControl</span><span>?</span><br> <br> <span class="hps">Here's the</span> <span class="hps">code I</span> <span class="hps"> have</span> <span class="hps">so far</span><span>:</span></p> <pre class="prettyprint">Public Class DistributionList Dim smtpClient As New System.Net.Mail.SmtpClient() Dim sentEmails As Integer Public Function SendMail(ByVal mailMessage As System.Net.Mail.MailMessage) As Integer AddHandler smtpClient.SendCompleted, AddressOf SmtpClient_OnCompleted sentEmails = 0 Dim recipients As DataTable = GetRecipients() For Each recipient As DataRow In recipients.Rows mailMessage.To.Clear() mailMessage.To.Add(New System.Net.Mail.MailAddress(recipient(&quot;Email&quot;), (recipient(&quot;DisplayName&quot;)))) SendMessage(mailMessage) Next Return sentEmails End Function Private Function GetRecipients() As DataTable Dim table As New DataTable() table.Columns.Add(&quot;DisplayName&quot;) table.Columns.Add(&quot;Email&quot;) Dim row As DataRow = table.NewRow() row(&quot;DisplayName&quot;) = &quot;John Doe&quot; row(&quot;Email&quot;) = &quot;John@example.com&quot; table.Rows.Add(row) Return table End Function Private Sub SendMessage(ByVal mailMessage As System.Net.Mail.MailMessage) Dim userState As Object = mailMessage Try smtpClient.SendAsync(mailMessage, userState) Catch failedRec As System.Net.Mail.SmtpFailedRecipientsException 'Choose to resend? 'Log failure of send here. Catch smtpExc As System.Net.Mail.SmtpException 'Log failure of SMTP client here. Catch ex As Exception 'Log exception here. End Try End Sub Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Dim mailMessage As System.Net.Mail.MailMessage = CType(e.UserState, System.Net.Mail.MailMessage) If (e.Error Is Nothing) Then sentEmails = sentEmails &#43; 1 Else 'Write to your error log here that an email failed. 'Possibly include information from the mailMessage. End If End Sub End Class</pre> <p><span></span><br> <br> <span class="hps">Hopefully</span> <span class="hps">someone</span> <span class="hps"> can</span> <span class="hps">help</span> <span class="hps">me on the way</span> <span class="hps"> to adjust</span> <span class="hps">the code.</span><br> <br> <span class="hps">Thanks in advance</span><span>.</span></p> 2012-01-21T11:30:41-05:004795945http://forums.asp.net/p/1761222/4795945.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Hi,</p> <p><br> If you want to read a list of recipients from a data source, assuming you database is Sql database, then you can use SqlConnection, SqlCommand, SqlDataAdapter class to return DataTable.</p> <p>For example:</p> <pre class="prettyprint">connStr = ConfigurationManager.ConnectionStrings[&quot;WEBDBConnectionString&quot;].ConnectionString; string cmdText = string.Empty; DataTable datatable = new DataTable(); using (SqlConnection sqlConn = new SqlConnection(connStr)) { cmdText = &quot;SELECT STU_NO,STU_NAME,STU_AGE FROM Student WHERE STU_NO='&quot; &#43; stuNo &#43; &quot;'&quot;; SqlCommand sqlComm = new SqlCommand(cmdText); sqlComm.Connection = sqlConn; SqlDataAdapter dataAadapter = new SqlDataAdapter(sqlComm); dataAadapter.Fill(datatable); return datatable; }</pre> <p>Here is a similar post related to send email to multiple recipients.<br> <a href="../../../../t/1135988.aspx">http://forums.asp.net/t/1135988.aspx</a></p> <p>If I misunderstood your meaning, please follow up here.</p> <p>&nbsp;</p> <p>Regards,<br> Peter</p> 2012-01-23T04:48:19-05:004796744http://forums.asp.net/p/1761222/4796744.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <pre><span class="hps">Hi</span><span>&nbsp;</span><span class="hps">Peter</span><span>,</span><br><span></span><span class="hps">Thank you for your</span><span>&nbsp;</span><span class="hps">response</span><span>,</span><br><br><span></span><span class="hps">I've</span><span>&nbsp;</span><span class="hps">tried</span><span>&nbsp;</span><span class="hps">with your</span><span>&nbsp;</span><span class="hps">anwser</span><span>&nbsp;</span><span class="hps">to</span><span>&nbsp;</span><span class="hps">get the</span><span>&nbsp;</span><span class="hps">correct</span><span>&nbsp;</span><span class="hps">code</span><span>&nbsp;</span><span class="hps">but</span><span>&nbsp;</span><span class="hps">it</span><span>&nbsp;</span><span class="hps">does not work</span><span>.</span><br><span></span><span class="hps">The</span><span>&nbsp;</span><span class="hps">emails</span><span>&nbsp;</span><span class="hps">must</span><span>&nbsp;</span><span class="hps">be</span><span>&nbsp;</span><span class="hps">sent</span><span>&nbsp;</span><span class="hps">with</span><span>&nbsp;</span><span class="hps">a</span><span>&nbsp;</span><span class="hps">WebUserControl.ascx</span><span>&nbsp;</span><span class="hps">page</span><span>,</span><span>&nbsp;</span><span class="hps">the code</span><span>&nbsp;</span><span class="hps">Should Be</span><span>&nbsp;</span><span class="hps">at the</span><span>&nbsp;</span><span class="hps">DistributieLijst.vb</span><span>.</span><br><br><span></span><span class="hps">The</span><span>&nbsp;</span><span class="hps">distributionlist.vb</span><span>&nbsp;</span><span class="hps">can</span><span>&nbsp;</span><span class="hps">not</span><span>&nbsp;</span><span class="hps">handle</span><span>&nbsp;</span><span class="hps">the code</span><span>&nbsp;</span><span class="hps">as</span><span>&nbsp;g</span><span class="hps">iven</span><span>&nbsp;</span><span class="hps">by: </span><span></span><span class="hps">ConfigurationManager.ConnectionStrings</span><span>.</span><br><span></span><span class="hps">The</span><span>&nbsp;</span><span class="hps">code give errors</span><span>.</span><span>&nbsp;</span><span class="hps atn">(</span><span>I</span><span>&nbsp;</span><span class="hps">am</span><span>&nbsp;</span><span class="hps">working</span><span>&nbsp;</span><span class="hps">with Microsoft</span><span>&nbsp;</span><span class="hps">Visual Web</span><span>&nbsp;</span><span class="hps">Developer</span><span>&nbsp;</span><span class="hps">2010</span><span></span><span class="hps">Express</span><span>)</span><br><span></span><span class="hps">I think</span><span>&nbsp;</span><span class="hps">the code</span><span>&nbsp;</span><span class="hps">modified</span><span>&nbsp;</span><span class="hps">to</span><span>&nbsp;</span><span class="hps">DistributieLijst.vb</span><span>&nbsp;</span><span class="hps">Should Be</span><span>.</span><br><span></span><span class="hps">The</span><span>&nbsp;</span><span class="hps">code</span><span>&nbsp;</span><span class="hps">below</span><span>&nbsp;</span><span class="hps">Should</span><span>&nbsp;</span><span class="hps">Be Replaced</span><span>&nbsp;</span><span class="hps">by</span><span>&nbsp;</span><span class="hps">a</span><span>&nbsp;</span><span class="hps">code,</span><span>&nbsp;</span><span class="hps">That</span><span>&nbsp;</span><span class="hps">reads</span><span>&nbsp;</span><span class="hps">the</span><span>&nbsp;</span><span class="hps">information</span><span>&nbsp;</span><span class="hps">from</span><span>&nbsp;</span><span class="hps">the</span><span></span><span class="hps">database,</span><span>&nbsp;</span><span class="hps">so</span><span>&nbsp;</span><span class="hps">thats the</span><span>&nbsp;</span><span class="hps">email</span><span>&nbsp;</span><span class="hps">get</span><span>&nbsp;</span><span class="hps">sent</span><br><span></span><span class="hps">to</span><span>&nbsp;</span><span class="hps">Various /</span><span>&nbsp;</span><span class="hps">multiple</span><span>&nbsp;</span><span class="hps">recipients</span><span>&nbsp;</span><span class="hps">in the database</span><span>.</span></pre> <p><span class="hps">&nbsp; This code</span><span>&nbsp;</span><span class="hps">sends an</span><span>&nbsp;</span><span class="hps">email to</span><span>&nbsp;</span><span class="hps">the</span><span>&nbsp;</span><span class="hps">recipient</span><span>&nbsp;</span><span class="hps">i.e.</span><span>&nbsp;</span><span class="hps">John Doe</span><span>.</span><br> <span></span><span class="hps">&nbsp; The code I</span><span>&nbsp;</span><span class="hps">need is</span><span>:</span><br> <span></span><span class="hps">&nbsp; Retrieve</span><span>&nbsp;N</span><span class="hps">ame and Email</span><span>&nbsp;A</span><span class="hps">ddress and</span><span>&nbsp;</span><span class="hps">sorted by</span><span>&nbsp;</span><span class="hps">zip</span><span>&nbsp;</span><span class="hps">code</span><span>&nbsp;</span><span class="hps">from a database</span><span>.</span></p> <p><span></span></p> <pre class="prettyprint">Private Function GetRecipients() As DataTable Dim table As New DataTable() table.Columns.Add(&quot;DisplayName&quot;) table.Columns.Add(&quot;Email&quot;) Dim row As DataRow = table.NewRow() row(&quot;DisplayName&quot;) = &quot;John Doe&quot; row(&quot;Email&quot;) = &quot;John@example.com&quot; table.Rows.Add(row) Return table</pre> <pre></pre> <pre> </pre> <pre>Do you have any idea?<br />Thank you,</pre> <pre><span>Regards,</span><br />tvw</pre> 2012-01-23T12:32:49-05:004806158http://forums.asp.net/p/1761222/4806158.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Hi,</p> <p><br> Have you add references to system.Configuration and use using statement (using System.Configuration) in your project? you don't need to place the database connection string in the web.config, you can directly use database connection string in your program, something like below:</p> <pre class="prettyprint">string connectionString=&quot;Data Source=(local);Initial Catalog=WEBDB;Integrated Security=True&quot;; SqlConnection sqlConn = new SqlConnection(connectionString)</pre> <p>and you can use order by in your sql query statement to sort by zip code.</p> <p>&nbsp;<br> Hope this helps</p> <p>Regards,<br> Peter</p> 2012-01-30T07:49:25-05:004816926http://forums.asp.net/p/1761222/4816926.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>hello,<br> Below is a new custom VB language code, but this unfortunately does not send mail to recipients.</p> <p>When debugging, the error in Email.ascx.vb:<br> The address parameter can not be an empty string.<br> Parameter name: address.<br> What needs to be changed?<br> Hoping for your help.<br> Regards,<br> TVW</p> <p><span style="text-decoration:underline">DistributionList.vb</span></p> <pre class="prettyprint">Imports System.Data.SqlClient Public Class DistributionList Dim smtpClient As New System.Net.Mail.SmtpClient() Dim sentEmails As Integer Private Property GetRecipients As New DataTable Public Function SendMail(ByVal mailMessage As System.Net.Mail.MailMessage) As Integer AddHandler smtpClient.SendCompleted, AddressOf SmtpClient_OnCompleted sentEmails = 0 Dim recipients As DataTable = GetRecipients() For Each recipient As DataRow In recipients.Rows mailMessage.To.Clear() mailMessage.To.Add(New System.Net.Mail.MailAddress(recipient(&quot;Email&quot;), recipient(&quot;Name&quot;))) SendMessage(mailMessage) Next Return sentEmails End Function Private Sub MakeMessage(ByVal mailMessage As System.Net.Mail.MailMessage) Dim queryString As String = _ &quot;SELECT Email, Name FROM recipients;&quot; Using connection As New SqlClient.SqlConnection(connectionString:=&quot;Data Source=|DataDirectory|\recipient.sdf&quot;) Dim command As New SqlClient.SqlCommand(queryString, connection) connection.Open() Dim reader As SqlClient.SqlDataReader = command.ExecuteReader() ' Call Read before accessing data. While reader.Read() End While ' Call Close when done reading. reader.Close() End Using End Sub Private Sub SendMessage(ByVal mailMessage As System.Net.Mail.MailMessage) Dim userState As Object = mailMessage Try smtpClient.SendAsync(mailMessage, userState) Catch failedRec As System.Net.Mail.SmtpFailedRecipientsException 'Choose to resend? 'Log failure of send here. Catch smtpExc As System.Net.Mail.SmtpException 'Log failure of SMTP client here. Catch ex As Exception 'Log exception here. End Try End Sub Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Dim mailMessage As System.Net.Mail.MailMessage = CType(e.UserState, System.Net.Mail.MailMessage) If (e.Error Is Nothing) Then sentEmails = sentEmails &#43; 1 Else 'Write to your error log here that an email failed. 'Possibly include information from the mailMessage. End If End Sub End Class</pre> <pre class="prettyprint">E<span style="text-decoration: underline;">mail.ascx.vb</span></pre> <pre class="prettyprint">Imports System.Net.Mail Partial Class Email Inherits System.Web.UI.UserControl Private _recipient As String Private Property recipient(p1 As String) As String Get Return _recipient End Get Set(value As String) _recipient = value End Set End Property Protected Sub btnSend_Click(ByVal sender As Object, e As System.EventArgs) Handles btnSend.Click Dim distList As New HDI.Net.Mail.DistributionList 'Create instance of main mail message class Dim mailMessage As New System.Net.Mail.MailMessage mailMessage.Priority = Net.Mail.MailPriority.High 'Configure mail mesage 'Set the From address with user input mailMessage.From = New System.Net.Mail.MailAddress(txtFrom.Text.Trim()) 'Get From address in web.config mailMessage.From = New System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings("fromEmailAddress")) mailMessage.Subject = txtSubject.Text.Trim() mailMessage.Body = txtBody.Text.Trim() Dim sentMails As Integer = distList.SendMail(mailMessage) 'Add one to many attachments 'mailMessage.Attachments.Add(New System.Net.Mail.Attachment("c:\temp.txt") 'Create an instance of the SmtpClient class for sending the email Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient() 'Use a Try/Catch block to trap sending errors 'Especially useful when looping through multiple sends Try smtpClient.Send(mailMessage) Catch smtpExc As System.Net.Mail.SmtpException 'Log error information on which email failed. Catch ex As Exception 'Log general errors End Try End Sub End Class </pre> <pre class="prettyprint"><span style="text-decoration: underline;"></span></pre> <p><span style="text-decoration:underline"></span></p> 2012-02-05T08:51:51-05:004826501http://forums.asp.net/p/1761222/4826501.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>At what line does it say that?</p> 2012-02-10T15:15:12-05:004827401http://forums.asp.net/p/1761222/4827401.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>In: Email.ascx.vb</p> <p>mailMessage.From = New System.Net.Mail.MailAddress(txtFrom.Text.Trim())</p> 2012-02-11T09:06:46-05:004831870http://forums.asp.net/p/1761222/4831870.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Then I am guessing there was nothing in txtFrom. On emails the From field is mandatory.</p> <p>Typically, this is taken care of using RequiredValidator. This will give the user a warning when the field is left empty, so it can be entered before actually doing anything.&nbsp;</p> 2012-02-14T14:58:41-05:004833806http://forums.asp.net/p/1761222/4833806.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Thank you for your response,</p> <p>When the From field is left blank I get the above error. And I can see in Web Developer:</p> <p>mailMessage = {MailMessage Mail System.Net..} mailMessage. From = Nothing txtFrom = {system.Web. TextBox Web controls, UI..} txtFrom .text = &quot;&quot;</p> <p>When a valid email address is entered in the From field nothing happens in Web Developer and the Email is not sent to the recipients from database. Maybe the below code is not correct.</p> <p>If you have any suggestions? Thanks in advance.</p> <pre class="prettyprint">'Set the From address with user input mailMessage.From = New System.Net.Mail.MailAddress(txtFrom.Text.Trim()) 'Get From address in web.config mailMessage.From = New System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings(&quot;FromEmailAddress&quot;))</pre> 2012-02-15T12:44:44-05:004837838http://forums.asp.net/p/1761222/4837838.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>The smtpClient.Send does happen?</p> <p>Have you been able to send email this way before?&nbsp;</p> 2012-02-17T15:10:28-05:004839540http://forums.asp.net/p/1761222/4839540.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p><span class="hps">Hi</span><span>,</span><span><br> &nbsp;</span></p> <p><span><span class="hps">I do not understand</span> <span class="hps">exactly what you</span> <span class="hps">meant by</span><span>: The smtpClient.Send does happen?</span></span></p> <p><span><span>But i can send email bij using the contactform with the same smtpClient.</span></span></p> <p><span><span></span></span></p> <p><span><span></span></span></p> 2012-02-19T09:13:47-05:004842962http://forums.asp.net/p/1761222/4842962.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Have you used the debugger to make sure the line with &quot;smtpClient.Send&quot; is executed?</p> <p>&nbsp;</p> <p>Good to see smtpClient can do Send. That means the focus is not on the connection to the SMTP server.</p> <p>&nbsp;</p> <p>The last code you posted fills the From field from a TextBox, and then overwrites it with a value from config. Do you want the value from the TextBox to be lost? And what is in the config?&nbsp;</p> 2012-02-21T11:14:18-05:004844904http://forums.asp.net/p/1761222/4844904.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Comment out: 'mailMessage.From = New System.Net.Mail.MailAddresSystem.Configuration.ConfigurationManager.AppSettings(&quot;FromEmailAddress&quot;))</p> <p><span class="hps">Debugging</span> <span class="hps">with</span> <span class="hps"> the</span> s<span class="hps">mpt</span> <span class="hps">client executed</span><span>.</span> <span class="hps">When</span> <span class="hps">not</span> <span class="hps">debugging</span> <span class="hps">nothing happens.</span></p> <p>config:</p> <pre class="prettyprint">&lt;appSettings&gt; &lt;add key=&quot;FromEmailAddress&quot; value=&quot;my@email.com&quot;/&gt; &lt;add key=&quot;HostName&quot; value=&quot;My.smtp.com&quot;/&gt; &lt;add key=&quot;Port&quot; value=&quot;25&quot;/&gt; &lt;add key=&quot;mailMessageFrom&quot; value=&quot;my@email.com&quot;/&gt; &lt;add key=&quot;Username&quot; value=&quot;myUsername&quot;/&gt; &lt;add key=&quot;UserPass&quot; value=&quot;mypassword&quot;/&gt; &lt;/appSettings&gt; &lt;!--Mail settings--&gt; &lt;system.net&gt; &lt;mailSettings&gt; &lt;smtp&gt; &lt;network host=&quot;My.smpt.com&quot; userName=&quot;myUsername&quot; password=&quot;mypassword&quot; port=&quot;25&quot;/&gt; &lt;/smtp&gt; &lt;/mailSettings&gt; &lt;/system.net&gt; &lt;!--Mail settings--&gt; &lt;system.web&gt;</pre> 2012-02-22T10:07:56-05:004848833http://forums.asp.net/p/1761222/4848833.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>Odd. Usually when SMTP client can't send a message, I get an Exception.</p> <p>&nbsp;</p> <p>So, when debugging the email is sent, but when not debugging it isn't?</p> <p>You may want to catch exceptions from smtpClient.Send. See if you can display any Message on the Exception in a Label on your page. See if that gets you anything.</p> <p>Also, you may want to display the fields of mailMessage in Labels on your page right before the smtpClient.Send.</p> <p>&nbsp;</p> 2012-02-24T08:25:32-05:004849230http://forums.asp.net/p/1761222/4849230.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p><span title="Dank u voor uw reactie's.">Thank you for your comment's.<br> </span><span title="Sorry, Debuggen met de SmptClient executed bedoel ik debuggen in VS 2010."></span></p> <p><span title="Sorry, Debuggen met de SmptClient executed bedoel ik debuggen in VS 2010.">Sorry, Debugging with SmptClient executed I mean debugging in VS 2010. </span><span title="De email wordt niet verzonden.">The email is not sent. </span> </p> <p><span title="De email wordt niet verzonden."><span title="Dim smtpClient As New System.Net.Mail.SmtpClient()">Can you give me an example of your proposal: display the fields in labels or mail message on my page right before the smtpClient.Send?</span></span></p> <p><span title="De email wordt niet verzonden."><span title="Dim smtpClient As New System.Net.Mail.SmtpClient()">Client Dim smtp As New System.Net.Mail.SmtpClient () </span></span></p> <p><span title="De email wordt niet verzonden."><span title="smtpClient = Nothing"><span title="smtpClient = Nothing">By debugging i can see this in VS: smtp client = Nothing </span></span><span title="exceptions from smtpClient:"></span></span></p> <pre class="prettyprint">System.Security.Cryptography.CryptographicException was Unhandled by user code Message = The handle is invalid. Source = mscorlib Stack Trace: at System.Security.SecureString.ProtectMemory () at System.Security.SecureString.InitializeSecureString (* Char value, Int32 length) at System.Security.SecureString .. ctor (char * value, Int32 length) at System.Net.UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString (String string plain) at System.Net.Configuration.SmtpNetworkElementInternal .. ctor (Smtp Network Element element) at System.Net.Configuration.SmtpSectionInternal .. ctor (Smtp Section section) at System.Net.Configuration.SmtpSectionInternal.GetSection () at System.Net.Mail.SmtpClient.get_MailConfiguration () at System.Net.Mail.SmtpClient.Initialize () at System.Net.Mail.SmtpClient .. ctor () at HDI.Net.Mail.DistributionList .. ctor () in C: \ Users \ Tvw \ Documents \ Visual Studio 2010 \ Projects \ WebSiteVB \ HDI.Net.Mail \ DistributionList.vb: line 8 at Email.btnSend_Click (Object sender, EventArgs e) in C: \ Users \ Tvw \ Documents \ Visual Studio 2010 \ WebSites \ WebSiteVB \ Email.ascx.vb: line 19 at System.Web.UI.WebControls.Button.OnClick (EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent (String event argument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (String event argument) at System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler source control, String event argument) at System.Web.UI.Page.RaisePostBackEvent (Name Value Collection postData) at System.Web.UI.Page.ProcessRequestMain (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) Inner Exception:</pre> <pre class="prettyprint"> &lt;%@ Control Language="VB" AutoEventWireup="false" CodeFile="Email.ascx.vb" Inherits="Email" %&gt; &lt;div&gt; &lt;div&gt; &lt;asp:Label ID="labFrom" runat="server" Text="From:" /&gt;&amp;nbsp;&lt;asp:TextBox ID="txtFrom" runat="server" /&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Label ID="labSubject" runat="server" Text="Subject:" /&gt;&amp;nbsp;&lt;asp:TextBox ID="txtSubject" runat="server" /&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Rows="10" Columns="80" /&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:Button ID="btnSend" runat="server" Text="Send Email" /&gt; &lt;/div&gt; &lt;/div&gt;</pre> 2012-02-24T12:00:44-05:004852334http://forums.asp.net/p/1761222/4852334.aspx/1?Re+How+can+I+modify+the+code+to+read+a+list+of+recipients+from+a+data+source+and+send+an+email+with+WebUserControl+Re: How can I modify the code to read a list of recipients from a data source and send an email with WebUserControl. <p>What I do in cases when the debugger doesn't cut it, is put Labels in my Page. Usually directly in the Page itself. Then, in the place I need to see the values from, I simply put these values on the Text properties of the Labels. That way I can see in the resulting page what the values were, and if any were not what I expected. For instance:</p> <pre class="prettyprint">labFrom.Text = mailMessage.From</pre> <p>&nbsp;</p> <p>And now you are getting an exception? That may be the problem.</p> <p>By default, VS2010 doesn't catch Exceptions in the debugger. And since UpdatePanel can eat Exceptions, they can go unnoticed.</p> <p>In VS2010, go to the Debug menu, and pick Exceptions. Turn on the Common Languate Runtime Exceptions. Then debug and see if you catch anything.&nbsp;</p> 2012-02-27T08:31:44-05:00