使用yahoo帐户发送emil,使用C#winform发送gamil [英] Send emil using yahoo account and gamil from C# winform

查看:93
本文介绍了使用yahoo帐户发送emil,使用C#winform发送gamil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每一个我做一个应用程序,从雅虎邮件发送电子邮件到gmail和雅虎邮件。

当我使用我的gamil帐户发送埃米尔它工作正常,但当我尝试使用我的发送埃米尔雅虎邮件帐户它给出了一个错误,请任何人帮助我。

当我使用此代码发送埃米尔使用我的雅虎帐户它给我错误

错误消息是follwoing



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";
           }

       }







< br $>







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);
           }
       }

推荐答案

忘记通过不同的服务器发送不同的帐户,这不是怎么回事电邮工作。您的网络管理员或您的网站管理员将拥有一个可以使用的SMTP服务器,该服务器可以从任何域运行,而是使用该服务器。



你不应该花时间做这些事情[ ^ ]
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[^]


雅虎邮箱端口号 - 谷歌搜索 [ ^ ]


这篇关于使用yahoo帐户发送emil,使用C#winform发送gamil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆