i use code
error : Invalid character found in the mail header
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MailMessage tbtMail = new MailMessage();
tbtMail.From = new MailAddress("deneme@gmail.com");
tbtMail.To.Add("deneme@gmail.com");
tbtMail.Bcc.Add(("deneme@gmail.com"));
tbtMail.Attachments.Add(new Attachment(@"C:\mailler.txt"));
tbtMail.Subject = "TES ET KONU";
tbtMail.Body = "TES ET";
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("deneme@gmail.com", "password");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.SendAsync(tbtMail, (Object)tbtMail);
}
private void btnTemizle_Click(object sender, EventArgs e)
{
lbMail.Items.Clear();
}
private void btnYukle_Click(object sender, EventArgs e)
{
try
{
dlgDosyaYukle.ShowDialog();
if (dlgDosyaYukle.FileName != "")
{
lbMail.Items.Clear();
StreamReader srRead = new StreamReader(dlgDosyaYukle.FileName);
while (srRead.EndOfStream == false)
{
lbMail.Items.Add(srRead.ReadLine().ToString());
}
srRead.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Hatalı Yükleme !\n\n" + ex.Message);
}
}
private void btnGonder_Click(object sender, EventArgs e)
{
try
{
MailMessage mesaj = new MailMessage();
mesaj.From = new MailAddress(txtMail.Text, txtMesaj.Text, System.Text.Encoding.UTF8);
SmtpClient smtp = new SmtpClient();
mesaj.Subject = txtKonu.Text;
mesaj.IsBodyHtml = false;
mesaj.BodyEncoding = System.Text.Encoding.UTF8;
mesaj.Body = txtGad.Text;
mesaj.Priority = MailPriority.High;
smtp.Credentials = new System.Net.NetworkCredential(txtMail.Text, txtParola.Text);
smtp.Port = Convert.ToInt32(txtPort.Text);
smtp.Host = txtSunucu.Text;
smtp.EnableSsl = true;
for (int i = 0; i < lbMail.Items.Count; i++) // Gönderilecek Maillerin Yüklenmesi.
{
mesaj.Bcc.Add(lbMail.Items[i].ToString());
}
smtp.Send(mesaj);
MessageBox.Show("Tüm Mailler Başarıyla Gönderildi");
}
catch (Exception ex)
{
MessageBox.Show("Mail Gönderiminde Hata oldu :\n\n" + ex.Message);
}
}
}
}