Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Aim:-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:-

Result:- The programme is executed successfully without any errors.

You might also like