- Posted by Admin on April 9, 2009
If you do not have an SMTP server of your own, you can still send SMTP authenticated emails from your .net application. Just sign up for a brand new gmail account or use your exisiting gmail account.
SmtpClient obj = new SmtpClient("smtp.gmail.com",465);
//465 is the TCP port for sending emails using gmail. 465 is generally used for SMTP with SSL.
obj.EnableSsl = true;
obj.Credentials=new System.Net.NetworkCredential("username@gmail.com", "password");
// your email address and its password for the SMTP authentication
MailMessage Mailmsg = new MailMessage();
Mailmsg.To.Clear();
Mailmsg.From = new MailAddress("username@gmail.com");
Mailmsg.Subject = "Subject";
Mailmsg.Body ="Body";
//adding attachments
Attachment at = new Attachment(Server.MapPath("~/document.doc"));
Mailmsg.Attachments.Add(at);
Mailmsg.Priority = MailPriority.High;
Mailmsg.IsBodyHtml = true;
Mailmsg.To.Add(new MailAddress("mailaddress", "name"));
Mailmsg.BodyEncoding = System.Text.Encoding.Default;
try
{
obj.Send(Mailmsg);
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
- Posted by Admin on April 7, 2009
You can use the below class to send the emails using asp.net form or any windows based .net applications. This implements the SMTP client to send email.
public class MyOwnSMTP
{
public void SendMail(string From, string To, string Sub, string Body)
{
MailMessage Email = new MailMessage(From, To, Sub, Body);
Email.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(SMTP server host or IP, 25 or 584);
smtp.Credentials = new System.Net.NetworkCredential("email address", "password");
smtp.Send(Email);
}
}
SMTP server hostname : The host name of your mail server. E.G. servers.a2zorkut.com
EMail address: Any email address hosted under the mail server at servers.a2zorkut.com
Password: Password of the above email address
From: From email address
To : To email address
Sub : Subject of the email to be sent.
Body: Body of the email to be sent.