DIGIT-ARC read-only archive · snapshot: July 23, 2026

how to send mail

2 posts · originally from https://geek.digit.in/community/threads/how-to-send-mail.162570/

J
jaykiran Original post #1
Aug 29, 2012 at 11:22 PM
hi friends,please tell me how to send email using asp.net
krishnandu.sarkar
Aug 29, 2012 at 11:32 PM
Code:
Imports System.Net.Mail

Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Dim message As String

SmtpServer.Credentials = New Net.NetworkCredential(<EMAILID>,<PASSWORD>)
'Only Needed if Your SMTP Port is Not the Default One.
SmtpServer.Port = 587
SmtpServer.Host = <MAIL SERVER> (Eg. mail.yourdomainname.com)
mail = New MailMessage()
mail.From = New MailAddress(<EMAILID>)
mail.To.Add(reciever)
mail.Subject = <SUBJECT>

message = "Hello World"

mail.Body = message

'This blocks main thread until mail is sent
'SmtpServer.Send(mail)
'MsgBox("mail send")

Dim userState As Object = mail

'Do this if you want to handle event manually, otherwise follow the below statement for sending mail asynchronously i.e. by not blocking the main thread.

'wire up the event for when the Async send is completed
'AddHandler SmtpServer.SendCompleted, AddressOf SmtpClient_OnCompleted

SmtpServer.SendAsync(mail, userState)

Hope that helps...

The code is in VB.NET, but in C# the procedure is same.

BTW, A simple google reveals...
1. *www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp

2. *asp.net-tutorials.com/misc/sending-mails/