Professional Documents
Culture Documents
Aim:-Source Code:-: Uses A Simple Web Form To Demonstrate How To Use The Smtpmail Class in The
Aim:-Source Code:-: Uses A Simple Web Form To Demonstrate How To Use The Smtpmail Class in The
.NET Framework
Source code:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace SMAIL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient sc = new SmtpClient();
sc.Host = "cec_it";
sc.Port = 25;
MailMessage msg = new MailMessage();
msg.From = new MailAddress(tbfrom.Text);
msg.To.Add( new MailAddress(tbto.Text));
msg.Subject = tbsubject.Text;
msg.Body = tbbody.Text;
msg.Priority = MailPriority.High;
if (txtattach.Text.Length > 0)
msg.Attachments.Add(new Attachment(txtattach.Text));
sc.Send(msg);
MessageBox.Show("mail send", "Result",MessageBoxButtons.OK);
}
catch
{
MessageBox.Show("error:");
}
}
private void btnbrowse_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
txtattach.Text = openFileDialog1.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
} }
Output:-