worker thread - how to?

G

Guest

Hi;

I need to have a worker thread that awakens every 15 minutes and then sends
some emails (sometimes).

1) What is the best way to set up the worker thread?

2) How do I access the IIS smtp server to send an email?
 
W

Walter Wang [MSFT]

Hi David,

Thank you for your post.

I think you can use a Timer and store it in Application states:

void Application_Start(object sender, EventArgs e)
{
Timer t = new Timer(3000);
t.Enabled = true;
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
Application["timer"] = t;
}

void t_Elapsed(object sender, ElapsedEventArgs e)
{
...
}

Regarding sending email, you can use SmtpClient from System.Net.Mail
namespace.

Unlike System.Web.Mail, which was introduced in the 1.0 Framework,
System.Net.Mail is not built upon the CDO/CDOSYS libraries. Instead it is
written from the ground up without any interop. Thus, it is not dependant
upon on other COM libraries. Although some functionality has been removed,
the new System.Net.Mail namespace is much more versatile than the older CDO
dependant System.Web.Mail.


SmtpClient mailObj = new SmtpClient( "name of the host");
MailMessage mail = new MailMessage("(e-mail address removed)",
"(e-mail address removed)", "Testing", "Hello Everybody");
mailObj.Send(mail);

You can also config the Host, Credentials and Port properties for
SmtpClient by using the settings in the application or machine
configuration files. For example:

<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="network">
<network
host="localhost"
port="25"
defaultCredentials="true"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Perfect. This is what I thought it was but I figure better to ask in case
there is a better way.
 
B

bruce barker \(sqlwork.com\)

one note. application_start will not fire until someone hits your site. also
the asp.net default is to automactally shutdown the site if there is no
usage. not a problem if you have a high volumne site.

-- bruce (sqlwork.com)




David Thielen said:
Perfect. This is what I thought it was but I figure better to ask in case
there is a better way.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Walter Wang said:
Hi David,

Thank you for your post.

I think you can use a Timer and store it in Application states:

void Application_Start(object sender, EventArgs e)
{
Timer t = new Timer(3000);
t.Enabled = true;
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
Application["timer"] = t;
}

void t_Elapsed(object sender, ElapsedEventArgs e)
{
...
}

Regarding sending email, you can use SmtpClient from System.Net.Mail
namespace.

Unlike System.Web.Mail, which was introduced in the 1.0 Framework,
System.Net.Mail is not built upon the CDO/CDOSYS libraries. Instead it is
written from the ground up without any interop. Thus, it is not dependant
upon on other COM libraries. Although some functionality has been
removed,
the new System.Net.Mail namespace is much more versatile than the older
CDO
dependant System.Web.Mail.


SmtpClient mailObj = new SmtpClient( "name of the host");
MailMessage mail = new MailMessage("(e-mail address removed)",
"(e-mail address removed)", "Testing", "Hello Everybody");
mailObj.Send(mail);

You can also config the Host, Credentials and Port properties for
SmtpClient by using the settings in the application or machine
configuration files. For example:

<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="network">
<network
host="localhost"
port="25"
defaultCredentials="true"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
W

Walter Wang [MSFT]

Thanks Bruce on this.

Hi David, if this is the issue, you may use Windows Service to do the job.


Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I think we're fine doing it in ASP.NET but the services is a good idea if we
every need it running 100% of the time.
 
W

Walter Wang [MSFT]

Hi David,

Thank you for your update.

Please let me know if you need help on Windows Service programming.

Have a nice day!

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top