.NET FAQs Unleashed!
Skip Navigation Links
Interview questions on Design Patterns in .NET
ASP.NET Ajax Interview Questions
Interview questions related to security
C# Interview Questions
ASP.NET Interview Questions
Interview Questions in ASP.NET 2.0
Articles at dotnetuncle.com
Skip Navigation Links
OOPs questions in .NET
Questions on .NET Framework
ADO.NET Interview Questions
Short Answer questions in .NET
Frequently asked differences in .NET
Important commonly used Acronyms in .NET
MS SQL, Oracle SQL Interview Questions
 
    
Dotnetuncle's Tip:

  .NET 4.0 introduces a new concept called dynamic binding. This is done using the keyword dynamic. A variable may be declared without specifying its data type and only using the dynamic keyword.

    

How to send an email using ASP.NET? How to use System.Web.Mail?

ASP.NET 2.0 provides the System.Web.Mail class to send a mail. This class may be used to send a mail using ASP.NET. See code below, by Ryan Olshan that explains how to use System.Web.Mail to send a mail using ASP.NET.

'Code in VB.NET
Imports System.Net.Mail
Public Class MailHelper
''' <summary>
''' Sends a mail message
''' </summary>
''' <param name="from">Sender address</param>
''' <param name="recepient">Recepient address</param>
''' <param name="bcc">Bcc recepient</param>
''' <param name="cc">Cc recepient</param>
''' <param name="subject">Subject of mail message</param>
''' <param name="body">Body of mail message</param>

Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String , ByVal subject As String, ByVal body As String)
' Instantiate a new instance of MailMessage
Dim mMailMessage As New MailMessage()
' Set the sender address of the mail message
mMailMessage.From = New MailAddress(from)
' Set the recepient address of the mail message
mMailMessage.To.Add(New MailAddress(recepient))

' Check if the bcc value is nothing or an empty string
If Not bcc Is Nothing And bcc <> String.Empty Then
   ' Set the Bcc address of the mail message
   mMailMessage.Bcc.Add(New MailAddress(bcc))
End If

' Check if the cc value is nothing or an empty value
If Not cc Is Nothing And cc <> String.Empty Then
  ' Set the CC address of the mail message
  mMailMessage.CC.Add(New MailAddress(cc))
End If

' Set the subject of the mail message
mMailMessage.Subject = subject
' Set the body of the mail message
mMailMessage.Body = body

' Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = True
' Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal

' Instantiate a new instance of SmtpClient
Dim mSmtpClient As New SmtpClient()
' Send the mail message
mSmtpClient.Send(mMailMessage)
End Sub
End Class

Add this in Web.config

<?xml version="1.0"?>
<configuration>
<system.net>
<mailSettings>
<smtp from="defaultEmail@yourdomain.com">
<network host="smtp.yourdomain.com" port="25" userName="yourUserName" password="yourPassword"/>
</smtp>
</mailSettings>
</system.net>
</configuration>

Page Redirection  Values Between Pages  Worker Process  Page Life Cycle  Global Variables  Postback  Server Control  Viewstate  Send Email  Namespace  Localization  Event Handler  Validation  Global.asax  HttpHandler  Session  Cookie  EnableViewState  Smart Navigation  Web Farm  Dataset  Register 


    
Dotnetuncle's Tip:

  The CLR has a program called the marshaler. This marshaler performs processes parameters in methods, and processes data between managed and unmanaged types.