Hi in this post i am telling how to send a mail without using smtp server. this is possible in web application i didn,t check in windows. By using System.web.Mail namespace it is possible
code in VB.Net
Imports System.Web.Mail
Public Shared Function SendEmail(ByVal FromAddress As String, ByVal ToAddress As String, ByVal CCAddress, ByVal BccAddress, ByVal EmailSubject As String, ByVal MessageText As String) As Boolean
Try
Dim objMailMessage As New MailMessage()
Dim obj As SmtpMail
obj.SmtpServer = “”
objMailMessage.From = FromAddress
objMailMessage.To = ToAddress
If CCAddress.Length > 0 Then
objMailMessage.Cc = CCAddress
End If
If BccAddress.Length > 0 Then
objMailMessage.Bcc = BccAddress
End If
objMailMessage.Subject = EmailSubject
objMailMessage.Body = MessageText
objMailMessage.BodyFormat = MailFormat.Html
obj.Send(objMailMessage)
Return True
Catch ex As Exception
WriteErrorToLog(GetExecutingScriptName() & ” - SendMail”, ex.Message)
Return False
End Try
End Function
To send a mail call the above function as
SendEmail(txtFromEmailID.Text.Trim(), txtToEmailID.Text.Trim(),”",”", txtSubject.Text.Trim(), strEMailText.ToString())
Code in C#.Net
using System.Web.Mail;
public static Boolean SendMail(string FromAddress,string ToAddress, string CCAddress, string BccAddress,string MailSubject, string MailBody)
{
try
{
System.Web.Mail.MailMessage msgMail = new MailMessage();
msgMail.From = FromAddress;
msgMail.To = ToAddress;
if (CCAddress.Length > 0)
{
msgMail.Cc = CCAddress;
}
if (BccAddress.Length > 0)
{
msgMail.Bcc = BccAddress;
}
msgMail.Subject = MailSubject;
msgMail.Body = MailBody;
msgMail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = “”;
SmtpMail.Send(msgMail);
return true;
}
catch (Exception ex)
{
return false;
}
}
call this function as
SendEmail(txtFromEmailID.Text.Trim(), txtToEmailID.Text.Trim(),”",”", txtSubject.Text.Trim(), strEMailText.ToString())
We can attach a file also to this mail.