The following article explained how to send email using webmail. To send an email you need a valid email account. You can use in the same way to send a SMTP mail from your Gmail account. You have to know the port number. By default you can port number 25 for webmail and 587 for Gmail.
Namespace
Namespace
using System.Net;
using System.Net.Mail;
Step: 1
Create a web form or windows form in visual Studio. I am using Visual Studio 2010 So i have created a windows form in visual studio 2010. You can follow the following picture.
Create a web form or windows form in visual Studio. I am using Visual Studio 2010 So i have created a windows form in visual studio 2010. You can follow the following picture.
Step: 2
Double click to the send button and write the following code. Use your valid email address and password for login your email account. ‘To Email, Subject Message, and Body Text’ of the email will retrieve from the text boxes from the windows form.
Double click to the send button and write the following code. Use your valid email address and password for login your email account. ‘To Email, Subject Message, and Body Text’ of the email will retrieve from the text boxes from the windows form.
.......................................................................
try
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("tanmoy@shrilekha.com", "www.shrilekha.com");
string tomail = toText.Text;
Msg.To.Add(tomail);
Msg.Subject = subjectText.Text;
string s=bodyText.Text;
Msg.Body = s.Replace(Environment.NewLine,"\n");
SmtpClient client = new SmtpClient();
client.Host = "webmail.shrilekha.com";
client.Port =25;
client.Credentials = new NetworkCredential("tanmoy@shrilekha.com", "Your password");
client.Send(Msg);
MessageBox.Show("Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
.............................................................................
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("tanmoy@shrilekha.com", "www.shrilekha.com");
string tomail = toText.Text;
Msg.To.Add(tomail);
Msg.Subject = subjectText.Text;
string s=bodyText.Text;
Msg.Body = s.Replace(Environment.NewLine,"\n");
SmtpClient client = new SmtpClient();
client.Host = "webmail.shrilekha.com";
client.Port =25;
client.Credentials = new NetworkCredential("tanmoy@shrilekha.com", "Your password");
client.Send(Msg);
MessageBox.Show("Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
.............................................................................
Output
run the project and Enter your data
Check the email inbox.
See it carefully the email is in Inbox
No comments:
Post a Comment