Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 亚马逊SES问题(发送消息)行_C# - Fatal编程技术网

C# 亚马逊SES问题(发送消息)行

C# 亚马逊SES问题(发送消息)行,c#,C#,我的代码运行良好,除了倒数第二行“client.Send(message);” 我检查了每个变量,它们都包含正确的信息 我在处理第二行之后立即抛出异常 错误消息:“可以简化对象初始化” 我用的是587端口 using (var client = new System.Net.Mail.SmtpClient(HOST, PORT)) { //pass smtp credentials

我的代码运行良好,除了倒数第二行“client.Send(message);”

我检查了每个变量,它们都包含正确的信息


我在处理第二行之后立即抛出异常


错误消息:“可以简化对象初始化”

我用的是587端口


                using (var client = new System.Net.Mail.SmtpClient(HOST, PORT))
                {
                    //pass smtp credentials
                    client.Credentials =
                        new NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);

                    //Enable SSL encryption
                    client.EnableSsl = true;

                    //Try to send the meessage. Show status in console.
                    try
                    {
                        Console.WriteLine("Attempting to send email...");
                        client.Send(message);
                        Console.WriteLine("Email sent!");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("The email was not sent.");
                        Console.WriteLine("Error messsage: " + ex.Message);
                    }
                }

你的第二行和最后一行有什么不好?您是否收到任何错误或其他信息?在处理第二行之后,我立即抛出异常,异常消息说什么?“可以简化对象初始化”这不是异常。这是Roslyn analyzer的信息。(请注意蓝色图标,而不是红色图标)。