Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I need code how to add mailer in an asp.net page to sending mails automatically to as enquiry request form.

Thanks
Raghav
Posted
Updated 29-Jun-11 3:01am
v2
Comments
Sergey Alexandrovich Kryukov 30-Jun-11 18:17pm    
Not a question. What's the problem?
--SA

Function to send email to multiple users also you need to add code into web.config file

VB
Public Sub SendEmail(ByVal emailAddress As String, ByVal Subject As String, ByVal Body As String)
        Dim message As New MailMessage

        Dim mf As New MailAddress("syscat@NYCT.com")
        'Dim mt As New MailAddress(emailAddress)
        Dim emailClient As New SmtpClient
        Dim a() As String = emailAddress.Split(";")

        Dim i As Integer
        Try
            For i = 0 To a.Length - 1
                If String.IsNullOrEmpty(a(i).ToString) = False Then
                    message.To.Add(a(i))
                End If
            Next


            message.From = mf
            message.IsBodyHtml = True
            message.Subject = Subject
            message.Body = Body
            emailClient.UseDefaultCredentials = True
            emailClient.Send(message)
        Catch e As Exception
        Finally
        End Try


    End Sub




Here is code for webconfig

XML
<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="youeemail@domain.com">
        <network host="192.168.1.1" port="25" defaultCredentials="true"/>
      </smtp>
    </mailSettings>
  </system.net>


you may need to add user is nam password for anthetication with smtp server
 
Share this answer
 
hi,
Most effective solution is to create a window service and install it at your server, if so check this link below,
Simple Windows Service Sample[^]
another solution is use Global.asax Application_OnStart, so that, as long as the web app is running, your "scheduler" is guaranteed to be running too.
check this link below
Simulate a Windows Service using ASP.NET to run scheduled jobs[^]
http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax[^]
you may find this link helpful
http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic-process-in-net-using.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900