Sending email from webpage

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Hey

..net 3.5

In my webproject I got a CreateUserWizard which contain this code for
sending confirmation email to the registered user:

<MailDefinition From="(e-mail address removed)" BodyFileName="~/MailFile.txt"
Subject="Confirmation">
</MailDefinition>

This sends email. But I don't like this solution. Here the senders email
address is hard coded into the source code. I want to be able to have
senders email address in web.config, so it easily can me modified without
the need to recompile the entire project... I'm not sure what is the best
tag in web.config for storing the email address... I assume when using
web.config, I must skip the MailDefinition tag and instead send email via
the behind code...

any suggestions?
 
<MailDefinition From=<%= ConfigurationManager.AppSettings["EmailAddress"] %>
BodyFileName="~/MailFile.txt" Subject="Confirmation">
</MailDefinition>

and in the web.config:
<appSettings>
<add key="EmailAddress" value="(e-mail address removed)" />
</appSettings>

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
the code you posted gives me several warnings and errors:

from the code you posted I removed a '=' from =<%=
ConfigurationManager.AppSettings
so I get =<% ConfigurationManager.AppSettings instead... I get fewer errors
then, the errors (some are warnings) I get then are listed below:

- Code blocks are not supported in this context
- Attribute values must be enclosed in quotation marks
- Content ('<MailDefinition From=') does not match any properties within a
'System.Web.UI.WebControls.CreateUserWizard', make sure it is well-formed.

any suggestions?


Eliyahu Goldin said:
<MailDefinition From=<%= ConfigurationManager.AppSettings["EmailAddress"]
%> BodyFileName="~/MailFile.txt" Subject="Confirmation">
</MailDefinition>

and in the web.config:
<appSettings>
<add key="EmailAddress" value="(e-mail address removed)" />
</appSettings>

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jeff said:
Hey

.net 3.5

In my webproject I got a CreateUserWizard which contain this code for
sending confirmation email to the registered user:

<MailDefinition From="(e-mail address removed)" BodyFileName="~/MailFile.txt"
Subject="Confirmation">
</MailDefinition>

This sends email. But I don't like this solution. Here the senders email
address is hard coded into the source code. I want to be able to have
senders email address in web.config, so it easily can me modified without
the need to recompile the entire project... I'm not sure what is the
best tag in web.config for storing the email address... I assume when
using web.config, I must skip the MailDefinition tag and instead send
email via the behind code...

any suggestions?
 
Oops, I copied it from a different context. The correct syntax for your case
is

<MailDefinition From="<%$ AppSettings: EmailAddress %>" ...

The <appSettings> section in the web.config is correct.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jeff said:
the code you posted gives me several warnings and errors:

from the code you posted I removed a '=' from =<%=
ConfigurationManager.AppSettings
so I get =<% ConfigurationManager.AppSettings instead... I get fewer
errors then, the errors (some are warnings) I get then are listed below:

- Code blocks are not supported in this context
- Attribute values must be enclosed in quotation marks
- Content ('<MailDefinition From=') does not match any properties within a
'System.Web.UI.WebControls.CreateUserWizard', make sure it is well-formed.

any suggestions?


Eliyahu Goldin said:
<MailDefinition From=<%= ConfigurationManager.AppSettings["EmailAddress"]
%> BodyFileName="~/MailFile.txt" Subject="Confirmation">
</MailDefinition>

and in the web.config:
<appSettings>
<add key="EmailAddress" value="(e-mail address removed)" />
</appSettings>

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jeff said:
Hey

.net 3.5

In my webproject I got a CreateUserWizard which contain this code for
sending confirmation email to the registered user:

<MailDefinition From="(e-mail address removed)" BodyFileName="~/MailFile.txt"
Subject="Confirmation">
</MailDefinition>

This sends email. But I don't like this solution. Here the senders email
address is hard coded into the source code. I want to be able to have
senders email address in web.config, so it easily can me modified
without the need to recompile the entire project... I'm not sure what
is the best tag in web.config for storing the email address... I assume
when using web.config, I must skip the MailDefinition tag and instead
send email via the behind code...

any suggestions?
 
Back
Top