how to send ? please tell me.
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 _
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// To avoid situations, when the program crashes because server rejection or
// invalid data, an exception handling mechanism is created.
try
{
// Creating a new SMTP Client. The server URL/IP is indicated as
// sendServer.Text (that is the text box with the data).
SmtpClient client = new SmtpClient(sendServer.Text);
// Creating a new mail message. The sender and receiver are
// indicated as sendFrom.Text and SendTo.Text
// (these are the text boxes with the data).
MailMessage message = new MailMessage(sendFrom.Text, sendTo.Text);
// The message body is the message content provided in the
// contentBox.
message.Body = contentBox.Text;
// The message subject is located in the subjectBox.
message.Subject = subjectBox.Text;
// To be able to send the message, it is necessary to provide the
// credentials on the server. The username is located in the userBox
// and the password is located in the passBox.
client.Credentials = new System.Net.NetworkCredential(userBox.Text, passBox.Text);
// Some servers require a specific port to connect,
// so it is specified in the serverPort text box.
if (serverPort.Text != null)
client.Port = System.Convert.ToInt32(serverPort.Text);
// Send the message.
client.Send(message);
}
// This catches the exceptions, if any.
catch (Exception ex)
{
// Show a message, explaining the problem.
MessageBox.Show("Cannot send message: " + ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
// Clear every field.
sendServer.Clear();
serverPort.Clear();
sendTo.Clear();
sendFrom.Clear();
userBox.Clear();
passBox.Clear();
subjectBox.Clear();
contentBox.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
MOD EDIT: When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 02 June 2011 - 03:55 AM
Reason for edit:: Added code tags

New Topic/Question
Reply



MultiQuote





|