Отправка вводимой информации на email - C#
Формулировка задачи:
Подскажите как написать код так чтобы человек ввел email и pass после нажатия кнопки START его email и pass отправились на почту пример шаблона прилагается
Решение задачи: «Отправка вводимой информации на email»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Net.Mail;
namespace rar_sending
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SendMail("smtp.yandex.ru", 25, "твоя_почта@yandex.ru", "пароль", "откуда@yandex.ru", "кому@yandex.ru", textBox1.Text, "Письмо - with rar archive", true, "C:\\ABBL22072010.rar");
}
public static void SendMail(string host, int port, string userName, string pswd, string fromAddress, string toAddress, string body, string subject, bool sslEnabled, string fileName)
{
Attachment att = new Attachment("C:\\ABBL22072010.rar");
MailMessage msg = new MailMessage(new MailAddress(fromAddress), new MailAddress(toAddress));
msg.Subject = subject;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = body;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Attachments.Add(att);
SmtpClient client = new SmtpClient(host, port);
client.Credentials = new System.Net.NetworkCredential(userName, pswd);
client.EnableSsl = sslEnabled;
try
{
client.Send(msg);
MessageBox.Show("Your message was sent successfully.");
}
catch (SmtpException ex)
{
MessageBox.Show("There was an error sending your message. {0}", ex.Message);
}
}
}
}