hi every one i make an application that send Email from yahoo mail to gmail and yahoo mail.
when i send emil using my gamil account it work fine but when i try to send emil using my yahoo mail account it give an error please any one help me.
when i use this code to send emil using my yahoo account it give me error
error message is follwoing
"
sending system.net.mail.smptException mailbox unavilable. the server response was requested mail action not taken mailbox unavilable
"
What I have tried:
Im using this code
private void SmptTypecomboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (SmptTypecomboBox1.SelectedIndex == 0)
{
portno =587;
servicetype = "smtp.gmail.com";
}
if (SmptTypecomboBox1.SelectedIndex == 1)
{
portno = 587;
servicetype = "smtp.mail.yahoo.com";
}
}
private void Sendbutton1_Click(object sender, EventArgs e)
{
using (OpenFileDialog attachement = new OpenFileDialog()
{
Filter = "Pdf Files|*.pdf",
ValidateNames = true
})
{
if (attachement.ShowDialog() == DialogResult.OK)
{
if (Isvalid())
{
Send(FromtextBox.Text, paswordtextBox.Text, TotextBox.Text, MessagetextBox.Text, AttachmenttextBox6.Text, servicetype, portno, attachement.FileName);
}
}
}
}
public void Send(string from, string password, string to, string Message, string subject, string host, int port, string file)
{
MailMessage email = new MailMessage();
email.From = new MailAddress(from);
email.To.Add(to);
email.Subject = subject;
email.Body = Message;
SmtpClient smtp = new SmtpClient(host, port);
smtp.UseDefaultCredentials = false;
NetworkCredential nc = new NetworkCredential(from, password);
smtp.Credentials = nc;
smtp.EnableSsl = true;
email.IsBodyHtml = true;
email.Priority = MailPriority.Normal;
email.BodyEncoding = Encoding.UTF8;
if (file.Length > 0)
{
Attachment attachment;
attachment = new Attachment(file);
email.Attachments.Add(attachment);
}
smtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallBack);
string userstate = "sending ...";
smtp.SendAsync(email, userstate);
}
private static void SendCompletedCallBack(object sender, AsyncCompletedEventArgs e)
{
string result = "";
if (e.Cancelled)
{
MessageBox.Show(string.Format("{0} send canceled.", e.UserState), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (e.Error != null)
{
MessageBox.Show(string.Format("{0} {1}", e.UserState, e.Error), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("your message is send", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}