Have you used the debugger to make sure the line with "smtpClient.Send" is executed?
Good to see smtpClient can do Send. That means the focus is not on the connection to the SMTP server.
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?
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Odd. Usually when SMTP client can't send a message, I get an Exception.
So, when debugging the email is sent, but when not debugging it isn't?
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.
Also, you may want to display the fields of mailMessage in Labels on your page right before the smtpClient.Send.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
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:
labFrom.Text = mailMessage.From
And now you are getting an exception? That may be the problem.
By default, VS2010 doesn't catch Exceptions in the debugger. And since UpdatePanel can eat Exceptions, they can go unnoticed.
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.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
tvw
Member
16 Points
9 Posts
Re: How can I modify the code to read a list of recipients from a data source and send an email w...
Feb 19, 2012 09:13 AM|LINK
Hi,
I do not understand exactly what you meant by: The smtpClient.Send does happen?
But i can send email bij using the contactform with the same smtpClient.
superguppie
All-Star
48225 Points
8679 Posts
Re: How can I modify the code to read a list of recipients from a data source and send an email w...
Feb 21, 2012 11:14 AM|LINK
Have you used the debugger to make sure the line with "smtpClient.Send" is executed?
Good to see smtpClient can do Send. That means the focus is not on the connection to the SMTP server.
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?
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
tvw
Member
16 Points
9 Posts
Re: How can I modify the code to read a list of recipients from a data source and send an email w...
Feb 22, 2012 10:07 AM|LINK
Comment out: 'mailMessage.From = New System.Net.Mail.MailAddresSystem.Configuration.ConfigurationManager.AppSettings("FromEmailAddress"))
Debugging with the smpt client executed. When not debugging nothing happens.
config:
<appSettings> <add key="FromEmailAddress" value="my@email.com"/> <add key="HostName" value="My.smtp.com"/> <add key="Port" value="25"/> <add key="mailMessageFrom" value="my@email.com"/> <add key="Username" value="myUsername"/> <add key="UserPass" value="mypassword"/> </appSettings> <!--Mail settings--> <system.net> <mailSettings> <smtp> <network host="My.smpt.com" userName="myUsername" password="mypassword" port="25"/> </smtp> </mailSettings> </system.net> <!--Mail settings--> <system.web>superguppie
All-Star
48225 Points
8679 Posts
Re: How can I modify the code to read a list of recipients from a data source and send an email w...
Feb 24, 2012 08:25 AM|LINK
Odd. Usually when SMTP client can't send a message, I get an Exception.
So, when debugging the email is sent, but when not debugging it isn't?
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.
Also, you may want to display the fields of mailMessage in Labels on your page right before the smtpClient.Send.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
tvw
Member
16 Points
9 Posts
Re: How can I modify the code to read a list of recipients from a data source and send an email w...
Feb 24, 2012 12:00 PM|LINK
Thank you for your comment's.
Sorry, Debugging with SmptClient executed I mean debugging in VS 2010. The email is not sent.
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?
Client Dim smtp As New System.Net.Mail.SmtpClient ()
By debugging i can see this in VS: smtp client = Nothing
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:<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Email.ascx.vb" Inherits="Email" %> <div> <div> <asp:Label ID="labFrom" runat="server" Text="From:" /> <asp:TextBox ID="txtFrom" runat="server" /> </div> <div> <asp:Label ID="labSubject" runat="server" Text="Subject:" /> <asp:TextBox ID="txtSubject" runat="server" /> </div> <div> <asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Rows="10" Columns="80" /> </div> <div> <asp:Button ID="btnSend" runat="server" Text="Send Email" /> </div> </div>superguppie
All-Star
48225 Points
8679 Posts
Re: How can I modify the code to read a list of recipients from a data source and send an email w...
Feb 27, 2012 08:31 AM|LINK
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:
And now you are getting an exception? That may be the problem.
By default, VS2010 doesn't catch Exceptions in the debugger. And since UpdatePanel can eat Exceptions, they can go unnoticed.
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.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.