Tag: smtpclient

无法使用斯堪的纳维亚字符向地址发送电子邮件

使用SmtpClient , MailMessage和MailAddress类,我无法发送到电子邮件地址,例如åbc.def@domain.se。 我得到错误/exception,如下所示: 邮件标题中找到了无效字符:’å’。 —————————发送邮件时出错——————– ——- System.Net.Mail.SmtpException:客户端或服务器仅配置为具有ASCII本地部分的电子邮件地址:åbc.def@domain.se。 在System.Net.Mail.MailAddress.GetUser(Boolean allowUnicode) 在System.Net.Mail.MailAddress.GetAddress(布尔allowUnicode) 在System.Net.Mail.MailAddress.Encode(Int32 charsConsumed,Boolean allowUnicode) System.Net.Mail.Mail.Message.Send上的System.Net.Mail.MailAddressCollection.Encode(Int32 charsConsumed,Boolean allowUnicode)处于System.Net.Mail.Message.PrepareHeaders(Boolean sendEnvelope,Boolean allowUnicode)处(BaseWriter writer,Boolean sendEnvelope) ,System.Net.Mail.SmtpClient.Send(MailMessage消息)中的布尔值allowUnicode) 我的主题/正文中的这些字符很好,但不在电子邮件地址中。 我已经尝试过设置SmtpClient.DeliveryMethod = SmtpDeliveryFormat.International ,或者MailMessage.HeadersEncoding = Encoding.Unicode (或UTF8 ),它似乎没有改变任何东西。 这些是我们需要与之沟通的人的真实电子邮件地址,因此这有点问题。 我一直在挖掘.Net源代码,但没有真正得到任何地方。 我追踪了一个ServerSupportsEai属性,谷歌告诉我EAI代表电子邮件地址国际化( https://tools.ietf.org/html/rfc5336 ),但是我的代码或者特定服务器是否有限制还不太清楚我正在谈论只是不支持这个……因为我正在使用测试服务器来避免向毫无戒心的瑞典人发送电子邮件! 有人可以帮助我清除这一点 – .Net是否支持这一点,如果是这样,如果我的客户端代码应该做什么来启用它呢?

我的ASP.NET应用程序如何从web.config自动获取SMTP设置?

我注意到我们总是这样: SmtpClient mSmtpClient = new SmtpClient(); // Send the mail message mSmtpClient.Send(mMailMessage); 并且设置凭据的唯一位置是web.config: 所以我的问题是,它是如何自动解决的?

C#SMTP无法在Outlook.com,端口587上进行身份validation。“服务器响应为:5.7.1客户端未通过身份validation”

我正在尝试发送自动电子邮件(真正需要的商业原因 – 不是垃圾邮件!)。 类似于下面的代码用于与另一个邮件服务提供商合作,但客户已转移到“outlook.com”,他们现在得到: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated 当然这个(C#)代码应该工作: private void Send_Click(object sender, EventArgs e) { MailMessage message = null; try { message = new MailMessage(From, To); message.Subject = “Update Request Session from ” + From; message.CC.Add(Cc); […]

System.Net.Mail.SmtpException:操作已超时。 asp.net中的错误使用godaddy托管发送邮件代码

我正在使用以下代码安静使用godaddy托管发送邮件。 但它抛出System.Net.Mail.SmtpException: The operation has timed out. protected void sendmail() { var fromAddress = “frommailid@site.com”; // any address where the email will be sending var toAddress = “to@gmail.com”; //Password of your gmail address const string fromPassword = “mypassword”; // Passing the values and make a email formate to display string subject = “HI test mail […]

Yahoo Mail的C#SMTP电子邮件发送代码失败但对其他服务器工作正常,有人可以帮忙吗?

我正在使用此代码通过yahoo SMTP服务器发送SMTP电子邮件,它是我正在编写的个人项目。 using System.Net.Mail; using System.Net; SmtpClient theClient = new SmtpClient(“smtp.mail.yahoo.com”, 465); theClient.UseDefaultCredentials = false; theClient.Credentials = new NetworkCredential(“username”, “password”); theClient.EnableSsl = true; MailMessage theMessage = new MailMessage(“username@yahoo.com”, “to.someone@gmail.com”); theMessage.Subject = “Dave test from C# subject”; theMessage.Body = “Dave test from C# body”; theClient.Send(theMessage); 它是用于发送SMTP电子邮件的非常标准的代码,但是…服务器似乎抛出错误。 它强行终止连接。 如果我使用其他SMTP服务器(如Gmail,Windows Live或其他各种ISP Smtp服务器),则不会发生这种情况。 这是exception和堆栈跟踪: System.IO.IOException: Unable to read data […]

尝试通过Office 365发送电子邮件时SMTP 5.7.57错误

我正在尝试设置一些代码以通过Office 365经过身份validation的SMTP服务发送电子邮件: var _mailServer = new SmtpClient(); _mailServer.UseDefaultCredentials = false; _mailServer.Credentials = new NetworkCredential(“test.user@mydomain.com”, “password”); _mailServer.Host = “smtp.office365.com”; _mailServer.TargetName = “STARTTLS/smtp.office365.com”; // same behaviour if this lien is removed _mailServer.Port = 587; _mailServer.EnableSsl = true; var eml = new MailMessage(); eml.Sender = new MailAddress(“test.user@mydomain.com”); eml.From = eml.Sender; eml.to = new MailAddress(“test.recipient@anotherdomain.com”); eml.Subject = “Test message”; […]

如何从Windows Phone 8应用程序发送电子邮件?

在Windows窗体项目中,我使用SmtpClient和MailMessage类来通过电子邮件发送信息。 是否有Windows Phone 8的等价物?

使用SmtpClient从Gmail发送电子邮件

我正在尝试通过SmtpClient连接到我的Gmail帐户,但它似乎无法正常工作。 我指定端口465,启用SSL并定义所有内容,但它需要2分钟,然后只显示一些错误消息未发送。 我在这做错了什么? try { MailMessage msg = new MailMessage(); msg.From = new MailAddress(“myemail@gmail.com); msg.To.Add(new MailAddress(“theiremil@email.com)); msg.Subject = “This is the subject”; msg.Body = “This is the body”; SmtpClient sc = new SmtpClient(“smtp.gmail.com”, 465); sc.EnableSsl = true; sc.UseDefaultCredentials = false; sc.Credentials = new NetworkCredential(“myemail@gmail.com”, “pass”); sc.DeliveryMethod = SmtpDeliveryMethod.Network; sc.Send(msg); erroremail.Text = “Email has been sent […]

我们是否需要在使用后在C#中处置或终止线程?

我有以下代码: public static void Send(this MailMessage email) { if (!isInitialized) Initialize(false); //smtpClient.SendAsync(email, “”); email.IsBodyHtml = true; Thread mailThread = new Thread(new ParameterizedThreadStart( (o) => { var m = o as MailMessage; SmtpClient client= new SmtpClient(“smtpserveraddress”); client.Send(m); })); mailThread.Start(email); 我希望邮件发送在后台完成而不会干扰主线程。 它完蛋后我不在乎。 我是否需要以某种方式处理创建的线程( mailThread )的处理? 还是在完成工作后会自动处理? 请不要推荐SendAsync方法。 我想手动创建线程。 Mail.Send只是一个示例场景。 谢谢。

通过http代理发送邮件

我正在尝试从通过Internet选项中设置的http代理连接到Internet的系统发送电子邮件。 我正在使用SmtpClient。 有没有办法通过此代理设置发送带有SmtpClient的邮件。 谢谢