Code for Sending E-Mail with System.Web.Mail?

Answers were Sorted based on User's Feedback



Code for Sending E-Mail with System.Web.Mail?..

Answer / vamshi

using System;
using System.Web.Mail;

namespace vamshi.SendMail
{
/// <summary>
/// Test console application to demonstrate sending e-
mail.
/// </summary>
class TestMail
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
TestMail.Send("testuser@yahoo.com",
"mstrawmyer@crowechizek.com",
"Test Message Using CDOSYS",
"Hello World! This is a simple message
sent
using CDOSYS.");
}

/// <summary>
/// Send a message using the .NET wrapper for
Collaborative Data
/// Objects (CDO). This method should be used when
sending to a
/// single recipient only; otherwise, the list of
recipients
/// will be known.
/// </summary>
/// <param name="MessageFrom">Message originator</param>
/// <param name="MessageTo">Message receipent</param>
/// <param name="MessageSubject">Message subject</param>
/// <param name="MessageBody">Message body</param>
public static void Send(string MessageFrom,
string MessageTo,
string MessageSubject,
string MessageBody)
{
MailMessage message = new MailMessage();
message.From = MessageFrom;
message.To = MessageTo;
message.Subject = MessageSubject;
message.BodyFormat = MailFormat.Text;
message.Body = MessageBody;

try
{
System.Console.WriteLine("Sending outgoing
message");
SmtpMail.Send(message);
}
catch( System.Web.HttpException exHttp )
{
System.Console.WriteLine("Exception occurred:" +
exHttp.Message);
}
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Code for Sending E-Mail with System.Web.Mail?..

Answer / ramesh

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;

public partial class email : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
NetworkCredential mylogin = new
NetworkCredential("yraddress@gmail.com","yourpassword");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("yraddress@gmail.com@gmail.com");
msg.To.Add(new MailAddress(TextBox1.Text));
// in Textbox1 you will put receiver gmail address,as this
example work with gmail only.
msg.Subject = TextBox2.Text;
// subject pass through textbox2
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = TextBox3.Text;
//msgbody pass through textbox3
msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;

SmtpClient client = new
SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = mylogin;
client.Send(msg);


}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ASP.NET Code Interview Questions

How to Snap the Cursor to a Button?

1 Answers  


How to get the row index on checking a Checkbox in a ListView

1 Answers   TCS,


how can we close a web page in asp.net without using jscript?

4 Answers  


Code for Using Keyboard Events?

0 Answers  


How we use ajax in asp.net through javaScript. Please givee me an example.

0 Answers  






How to Export Data to Excel?

4 Answers   Eastcom Systems,


Coding for Synchronizing Cache Access in ASP.NET?

0 Answers  


Code for Communicating over Sockets?

0 Answers  


How to Create Scrollable Micro Windows?

2 Answers  


HOw to Build a Nested GridView Control with ASP.NET?

2 Answers  


Give coding for Exception Handling Techniques in ASP.NET?

3 Answers   Microsoft,


working with fileUpload ?

1 Answers  


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)