Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);
}
}

}
}
Posted
Comments
[no name] 3-Jul-15 8:40am    
change gmail login security not to use the 2-step verification, but only a password.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900