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


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.Send(email);
           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);
           }
       }
Posted
Updated 5-Sep-18 0:41am
v2

Forget sending through different servers for different accounts, that's not how email works. Your network admin or your webhost will have an SMTP server that you can use that will work to\from any domain, use that server instead.

Things you shouldn't spend time doing[^]
 
Share this answer
 
 
Share this answer
 
Comments
Fahid Zahoor 5-Sep-18 6:06am    
i try this but it give an error
i use port no 995
failure :sending field
now tell me what can i do
Richard MacCutchan 5-Sep-18 6:18am    
Go to the Yahoo mail website and get the complete details for sending mail using their SMTP server. However, you may find that they do not accept mail requests in this way.
Fahid Zahoor 14-Sep-18 5:32am    
ok thanks i will try

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