send email through SMTP in ASP.net

 Imports System.Net
Imports System.IO
Imports System.Net.Mail

Following is the Code

  Private Function SendEmail(ByVal mailfrom As String, ByVal mailto As String, ByVal cc As String, ByVal bcc As String, ByVal subject As String, ByVal message As String, ByVal attach1 As String, ByVal attach2 As String, ByVal userid As String, ByVal pwd As String) As String
        Try
            'create the mail message
            Dim mail As New MailMessage()

            'set the addresses
            mail.From = New MailAddress(mailfrom)
            mail.To.Add(mailto)
            mail.CC.Add(cc)
            'mail.Bcc.Add(bcc)

            'set the content
            mail.IsBodyHtml = True
            mail.Subject = subject
            mail.Body = message

            ' add an attachment from the filesystem
            mail.Attachments.Add(New Attachment(attach1))

            'to add additional attachments, simply call .Add(...) again
            '  mail.Attachments.Add(New Attachment(attach2))
            ' mail.Attachments.Add(New Attachment("c:\temp\example3.txt"))

            'send the message
            Dim mailClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
            Dim d As New dbOperation
         
            'This object stores the authentication values
            Dim basicCredential As System.Net.NetworkCredential = New System.Net.NetworkCredential("xyz@dd.com", "pwd")
            mailClient.Host = "10.0.8.220"
            mailClient.UseDefaultCredentials = False
            mailClient.Credentials = basicCredential
            mailClient.Send(mail)
            Return "ok"
        Catch exp As Exception

            Return "Error: " & exp.Message
        End Try



Comments

Most Viewed Post

solution for facebook static.ak.fbcdn.net waiting

Connect Sony XPLOD MEX-BT2500 Bluetooth CD Receiver with ur mobile

Crystal Report : Show data horizontally (Left to right) i.e. columns as rows

Google+ Followers