Sending email from webpage

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?
 
E

Eliyahu Goldin

<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
 
J

Jeff

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?
 
E

Eliyahu Goldin

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top