Results 1 to 10 of 10

Thread: Sending email automatically?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    7

    Sending email automatically?

    Helo, how to automate sending email? I want to automatically send email to some addresses every day? How can i do that?
    I build that one for my final project at my college. Please help me.
    Thanks in advance.
    I am using this code....
    try
    Dim objEmailMessage As System.Web.Mail.MailMessage
    Dim objSMTPServer As System.Web.Mail.SmtpMail
    objSMTPServer.SmtpServer = "mail.wefgroup.com"

    objEmailMessage = New System.Web.Mail.MailMessage
    With objEmailMessage
    .To = "[email protected]"
    .From = "[email protected]"
    .Subject = "Helo"
    .Body = "I test sending email"

    End With

    objSMTPServer.Send(objEmailMessage)
    catch exc as exception
    response.write(exc.innerexception.innerexception.message)
    end try
    Make A Project for Assignment using VB.Net and ASP.Net

  2. #2
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    You could always just make a VB.NET exe and then schedule it under windows scheduler...

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    7

    Alternative ways?

    Is there any alternatives to send email automatically other than Windows Scheduler?

    Thanks...
    Make A Project for Assignment using VB.Net and ASP.Net

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Start a timer when the web application starts up. Then, on fire, check the time, if it is the time to fire off the email, then do it, otherwise do nothing.

    This is probably horribly inefficient though for a web app, not sure.

    You could create a windows service, install it, and let it run in the background.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    7
    helo, thanks for your reply.
    How can i check whether the web application is started up?
    I want the email send automatically everyday to the user...
    How should i code it?
    Make A Project for Assignment using VB.Net and ASP.Net

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Use the events in the Global.asax file.
    I think Application Start is the one you want...not sure.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    7
    Originally posted by hellswraith
    Use the events in the Global.asax file.
    I think Application Start is the one you want...not sure.

    Thanks.
    U mean all we need it just place the email code part at the Application Start in the Global.asax?
    Make A Project for Assignment using VB.Net and ASP.Net

  8. #8
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    can you try this In your global.ascx
    VB Code:
    1. Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    2.         ' Fires when the application is started
    3.         Dim myTimer As New System.Timers.Timer
    4.         myTimer.Interval = 5000
    5.         AddHandler myTimer.Elapsed, AddressOf myTimer_Elapsed
    6.         myTimer.Enabled = True
    7.     End Sub
    8.  
    9.     Protected Sub myTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
    10.         'run your code that determines if it time to send emails
    11.         'and if so call procedure/function that sends them
    12.     End Sub

    Timer interval is in milliseconds so in your case you'll probably want it to be a lot bigger than 5000.

    EDIT: I suppose you could even set the timer interval to 86400000 (1 day) but then you are relying on the server to be running 24 hours a day without any problems which isn't a good idea.
    Last edited by Fishcake; Jun 17th, 2004 at 07:06 AM.

  9. #9
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    EDIT: I suppose you could even set the timer interval to 86400000 (1 day) but then you are relying on the server to be running 24 hours a day without any problems which isn't a good idea.
    This isn't a good idea for another reason possibly. ASP.NET apps will end if there is no activity. I don't know if having a timer going would prevent it from stopping or not. Only testing would expose everything.

  10. #10
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Question httpModule..?

    What about an HttpModule? You install the module in the WebConfig
    Code:
    <httpModules>
        <add name="Timer" type="TimerModule, TimerModule" />
    </httpModules>
    You inherit System.Web.IHttpModule(I think that's right.) and override OnBeginRequest? That means every request your OnBeginRequest is fired and whatever code is there runs. It needs to be fast. Super duper fast.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width