WebException无法连接到远程服务器

时间:2016-09-05 15:58:30

标签: c# embedded windows-ce

我在智能设备掌上电脑(Honeywell Dolphin)中有一个项目,用于在SQL Compact数据库中设置数据。我需要帮助的是通过电子邮件中的附件(excel文件)导出插入数据库的数据。

实际上,我处理的电子邮件是直接从智能设备调用,但不识别某些库,如“System.Net.Mail”。有人建议使用OpenNETCF.Net.Mail和OpenNETCF.Net库,但这些不允许附加文件,所以我开始调查并收到建议通过网站进行,但问题是,当我从智能设备拨打电话并从实际设备项目运行它时,我得到了错误“WebException:无法连接到远程服务器”检查它以及是否存在被亵渎的互联网。

我使用的邮件代码是:

[WebMethod]
public void Correo()
{
    MailMessage objeto_mail = new MailMessage();
    SmtpClient client = new SmtpClient();
    client.Port = 25;
    client.Host = "smtp.live.com";
    client.Timeout = 100000000;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("email", "Password");
    objeto_mail.From = new MailAddress("email ");
    objeto_mail.To.Add(new MailAddress("email "));
    objeto_mail.Subject = "Pedidos";
    List<string> Archivo = new List<string>();
    Archivo.Add("");
    Archivo.Add("");
    objeto_mail.IsBodyHtml = false;
    objeto_mail.Body = "se hizo el pedido y la orden esta adjuntada en el correo con un excell";
    client.EnableSsl = true;
    using (var stream = new MemoryStream())
    using (var writer = new StreamWriter(stream))
    {
        writer.WriteLine();  // here you should be the information in the database
        writer.Flush();
        stream.Position = 0;
        objeto_mail.Attachments.Add(new Attachment(stream, "Pedido.cvs", "text/csv"));
        client.Send(objeto_mail);
    }
}

0 个答案:

没有答案
相关问题