标签: smtpclient

C# - 无法通过Gmail SMTP在WIndows Azure中发送邮件

这是我的Web.config:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network">
            <network defaultCredentials="true" enableSsl="true" host="smtp.gmail.com" port="25" userName="xxxxxxx@gmail.com" password="xxxxxxxxxxx"/>
        </smtp>
    </mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)

我的方法:

public static void EmailVerification(string email, string nickname)
    {
        MailAddress from = new MailAddress("xxxxxxxxxxx", "xxxxxxxxxxxx");
        MailAddress to = new MailAddress(email);

        MailMessage message = new MailMessage(from, to);

        message.Subject = "Test";
        message.Body = "Test";
        SmtpClient client = new SmtpClient();

        try
        {
            client.Send(message);
        }
        catch(SmtpFailedRecipientException ex)
        {
            HttpContext.Current.Response.Write(ex.Message);
            return;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的失败SmtpException:

Failure sending mail.
Run Code Online (Sandbox Code Playgroud)

的InnerException:

Unable to connect to the remote server
Run Code Online (Sandbox Code Playgroud)

我在本地测试它,但我想它应该工作.我必须在Windows Azure上运行它,我尝试过它也没有用.有什么我想念的吗?

azure smtpclient

14
推荐指数
1
解决办法
9775
查看次数

我可以从SmtpClient.SendAsync的userToken对象中获得什么好处?

我用SMTPClient.Send(mail)的方法来发送电子邮件,但后来我看到,如果电子邮件ID不存在(不存在),我的应用程序等待,直到它接收到异常,然后允许用户执行其他任务.

所以我想到了使用SMTPClient.SendAsync方法.

我怀疑!! 这个userToken对象在哪里可以作为参数传递给方法?我在网上搜索了很多东西,但没有找到一个很好的例子.即使在MSDN中,他们也会这样使用它

string userState = "test message1";
client.SendAsync(message, userState);
Run Code Online (Sandbox Code Playgroud)

但那么它真正可以用于什么呢?

先感谢您.

c# sendmail smtpclient sendasync winforms

14
推荐指数
1
解决办法
1万
查看次数

与SmtpClient.UseDefaultCredentials属性混淆

在我的MVC4应用程序中,我使用它SmtpClient通过Gmail的smtp.gmail.comSMTP服务器发送电子邮件.

我已使用以下设置配置了我的Web.Config文件:

<system.net>
 <mailSettings>
  <smtp deliveryMethod="Network">
   <network enableSsl="true" 
   defaultCredentials="false" 
   host="smtp.gmail.com" 
   port="587" 
   userName="xxMyUserNamexx@gmail.com" 
   password="xxMyPasswordxx" />
  </smtp>
 </mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)

使用SmtpClient并发送电子邮件消息的方法如下所示:

public void SendMail(string fromDisplayName, string fromEmailAddress, string toEmailAddress, string subject, string body)
{
    MailAddress from = new MailAddress(fromEmailAddress, fromDisplayName);
    MailAddress to = new MailAddress(toEmailAddress);
    MailMessage mailMessage = new MailMessage(from, to);
    mailMessage.Body = body;
    mailMessage.Subject = subject;

    SmtpClient client = new SmtpClient();
    //client.UseDefaultCredentials = false;
    client.Send(mailMessage);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码按预期工作,很好.令我困惑的是注释行client.UseDefaultCredentials = false;- 如果我要取消注释该行,我将收到一条异常消息,指出:

SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.5.1需要身份验证.

更重要的是,如果我将UseDefaultCredentials属性设置为true或者 …

asp.net-mvc smtpclient

14
推荐指数
2
解决办法
2万
查看次数

无需更改 .NET 中的代码即可启用 TLS 1.2

我有 .NET 4.5.2 应用程序用于SmtpClient发送电子邮件。该应用程序安装在Windows 2012 R2服务器上。当我禁用 TLS 1 和 TLS 1.1 并仅启用 TLS 1.2 时,应用程序停止发送邮件。我认为这是因为 .NET 4.5.2 不支持 v1.2。

我正在考虑以下步骤

1> 在 Windows Server 上禁用 TLS 1 和 TLS 1.1,仅启用 TLS 1.2。
2>在Windows服务器上安装.NET 4.8。
3>将应用程序的目标框架更改为4.8(在csproj和web.config中)并重新编译。
4>部署应用程序。


基于文档的 问题Starting with .NET Framework 4.7.1, WCF defaults to the operating system configured version
1>这仅适用于 WCF 还是 SMTP 也默认为操作系统配置的版本?
2> 或者我是否需要明确设置版本,例如System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
3> 现在是否可以设置版本 TLS 1.2,并且将来 TLS 1.3 可用时应用程序应自动默认为 TLS 1.3?(无需再次更改代码)

.net c# smtpclient tls1.2 .net-4.8

14
推荐指数
1
解决办法
3万
查看次数

smtpclient"发送邮件失败"

这是我的代码

for(int i = 0; i < number ; i++)
{
MailAddress to = new MailAddress(iMail.to);
MailAddress from = new MailAddress(iMail.from, iMail.displayName);
string body = iMail.body;
string subject = iMail.sub;
oMail = new MailMessage(from, to);
oMail.Subject = subject;
oMail.Body = body;
oMail.IsBodyHtml = true;
oMail.Priority = MailPriority.Normal;
oMail.Sender = from;
s = new SmtpClient(smtpServer);
if (s != null)
{
 s.Send(oMail);
}
oMail.Dispose();
s = null;
}
Run Code Online (Sandbox Code Playgroud)

这个循环发送超过60,000封电子邮件.但是我的问题是我在一些电子邮件中发送"发送邮件失败"了5000次,而且剩下的时间少了一些时间.我检查了所有那些错误,电子邮件有有效的电子邮件地址.不知道是什么问题.我真的需要帮助.

编辑:这是我的异常跟踪

错误 - 发送邮件失败.Inner Ex - System.IO.IOException:无法从传输连接中读取数据:net_io_connectionclosed.在System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字节[]缓冲液,的Int32偏移的Int32读,布尔的readLine)在System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader呼叫者,布尔ONELINE)在System.Net.Mail.SmtpReplyReaderFactory .ReadLine(SmtpReplyReader呼叫者)在System.Net.Mail.CheckCommand.Send在System.Net在System.Net.Mail.MailCommand.Send(SmtpConnection康恩,字符串&响应)(康涅狄格州SmtpConnection,字节[]命令,从字符串). Mail.SmtpTransport.SendMail(MailAddress sender,MailAddressCollection recipients,String deliveryNotify,SmtpFailedRecipientException&exception)

.net c# smtpclient

13
推荐指数
2
解决办法
9万
查看次数

smtpClient.send()和smtpClient.SendAsync()之间的区别?

我正在尝试从localhost发送邮件..

并且在这样做我有从不同的网站发送邮件的方法.. 但在这样做我感到困惑smtpClient.send()smtpClient.SendAsync()..

我想知道他们是如何彼此不同的???

提前致谢..

smtpclient

13
推荐指数
1
解决办法
1万
查看次数

SmtpClient从发送服务器获取结果

SmtpClient发送方法返回void.有没有办法得到服务器响应?除非它抛出异常,我才假设它成功了吗?

我指的是...... http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

.net c# system.net.mail smtpclient

13
推荐指数
2
解决办法
3万
查看次数

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 ";
        string body = "From: pro@e-hotelspro.com";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
        {
            //smtp.Host = "relay-hosting.secureserver.net";
            smtp.Host = "smtpout.secureserver.net";
            smtp.Port = 80; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net sendmail smtpclient

13
推荐指数
1
解决办法
3万
查看次数

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

在Windows窗体项目中,我使用SmtpClient和MailMessage类来通过电子邮件发送信息.

Windows Phone 8是否有相同的功能?

c# smtpclient mailmessage windows-phone-8

13
推荐指数
3
解决办法
9406
查看次数

如何通过Gmail发送带有C#的电子邮件

尝试通过我的Web服务发送电子邮件时出错.我已尝试启用访问不太安全的应用程序,禁用两步验证并通过Web浏览器登录帐户.SO的解决方案都没有对我有用.我还是得到:

错误:System.Net.Mail.SmtpException:SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.5.1需要身份验证.

我该怎么做才能解决这个问题?

namespace EmailService
{
    public class Service1 : IService1
    {    
        public string SendEmail(string inputEmail, string subject, string body)
        {
            string returnString = "";
            try
            {
                MailMessage email = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";

                // set up the Gmail server
                smtp.EnableSsl = true;
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "mypassword");
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;

                // draft the email
                MailAddress fromAddress = new MailAddress("cse445emailservice@gmail.com");
                email.From = fromAddress;
                email.To.Add(inputEmail);
                email.Subject = body;
                email.Body …
Run Code Online (Sandbox Code Playgroud)

c# gmail smtp smtpclient

13
推荐指数
1
解决办法
5万
查看次数