Email send through on localhost or web

22 Mar


First Write server setting in webconfig

  <!–Start SMTP Settings –>
    <add key=”ServerName” value=”″/>
    <add key=”smtpUser” value=””/>
    <add key=”smtpPassword” value=”123″/>
    <add key=”smtpPort” value=”25″ />
    <!–End SMTP Settings –>
    <add key=”From” value=””/>
    <!– Start Form ToEmail –>
    <!– Start Form ToEmail –>

 <add key=”email_To” value=” “/>
    <add key=”email_CC” value=””/>
    <add key=”email_BCC” value=””/>
    <add key=”email_Subject” value=”Contact Us Form from the test Website”/>

For localhost you want to see the e-mail for testing porposes you create Email folder in any drive just write this code in webconfig

      <smtp deliveryMethod=”SpecifiedPickupDirectory”>

        <specifiedPickupDirectory pickupDirectoryLocation=”d:\Emals\”/>
write this code on button click event

 SendEmail(AppSettings(“email_To”), AppSettings(“email_CC”), AppSettings(“email_BCC”), AppSettings(“email_Subject”), sbMessage.ToString(), AppSettings(“from”))

Create a function in

 Public Sub SendEmail(ByVal EmailTo As String, ByVal EmailCC As String, ByVal EmailBCC As String, ByVal EmailSubject As String, ByVal EmailBody As String, ByVal EmailFrom As String)
        Dim smtpClient As New SmtpClient()
            If AppSettings(“ServerName”) <> “” Then
                smtpClient.Host = AppSettings(“ServerName”)
                If (AppSettings(“ServerName”).Length > 0) Then
                    smtpClient.Port = AppSettings(“smtpPort”)
                End If
                If (AppSettings(“smtpUser”).Length > 0) Then
                    smtpClient.Credentials = New NetworkCredential(AppSettings(“smtpUser”), AppSettings(“smtpPassword”))
                End If
                Dim emailMessage As New MailMessage()
                emailMessage.To.Add(New MailAddress(EmailTo))
                If EmailCC <> “” Then
                    emailMessage.CC.Add(New MailAddress(EmailCC))
                End If
                If EmailBCC <> “” Then
                    emailMessage.Bcc.Add(New MailAddress(EmailBCC))
                End If
                ‘smtpClient.DeliveryMethod = smtpClient.PickupDirectoryLocation

                emailMessage.From = New MailAddress(EmailFrom)
                emailMessage.Body = EmailBody
                emailMessage.Subject = EmailSubject
                emailMessage.IsBodyHtml = True
                emailMessage.Priority = MailPriority.Normal
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

1 Comment

Posted by on March 22, 2011 in ASP Dot Net C#


One response to “Email send through on localhost or web

  1. paul

    February 1, 2014 at 6:24 pm



Leave a Reply to paul Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: