Wednesday, August 31, 2005

Send mail using SMTP

following function can be added in a utility class and 
can be called from the application with parameters to send email.

SMTP Server IP could be stored in web.config or database, so that 
it can be changed easily.

Imports System.Web.Mail ' namespace is required for smtp mail

Public Shared Function SendMail(ByVal fromAddress As String, _
      ByVal toAddress As String, ByVal ccAddress As String, _
      ByVal bccAddress As String, ByVal msgSubject As String, _
      ByVal msgBody As String, ByVal smtpServer As String, _
      Optional ByVal msgPriority As Int32 = 0, _
      Optional ByVal msgFormat As Int32 = 0) As Boolean
 Dim mailMsg As MailMessage
 Try
  mailMsg = New MailMessage
  mailMsg.From = ConvertToString(fromAddress)
  mailMsg.To = ConvertToString(toAddress)
  If ConvertToString(ccAddress).Length > 0 Then mailMsg.Cc = ccAddress
  If ConvertToString(bccAddress).Length > 0 Then mailMsg.Bcc = bccAddress
  mailMsg.Subject = ConvertToString(msgSubject)
  mailMsg.Body = ConvertToString(msgBody)

  If msgPriority < priority =" MailPriority.Low"> 0 Then
    mailMsg.Priority = MailPriority.High
  Else
    mailMsg.Priority = MailPriority.Normal
  End If

  If msgFormat > 0 Then
    mailMsg.BodyFormat = MailFormat.Html
  Else
    mailMsg.BodyFormat = MailFormat.Text
  End If
  SmtpMail.SmtpServer = smtpServer
  SmtpMail.Send(mailMsg)
  Return True
 Catch
  Return False
 End Try
End Function

1 comment:

Anonymous said...

Hi,

I mostly visits this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]shivamdotnet.blogspot.com is filled with quality info. Frankly speaking we really do not pay attention towards our health. Here is a fact for you. Recent Research shows that about 70% of all USA grownups are either chubby or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Hence if you're one of these people, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss[/url] is not like piece of cake. Some improvement in of daily activity can help us in losing weight quickly.

About me: I am webmaster of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health trainer who can help you lose weight quickly. If you do not want to go under difficult training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for quick weight loss.