Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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/7/sql-server/23.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
Asp.net m、 Net.Mail.MailMessage“”不包含“密件抄送”的定义,并且找不到接受类型为的第一个参数的扩展方法“密件抄送”,并且在“SendMessage(MailMessage)”行错误6后出现一条红色扭曲线;预期,当我添加它时,它将抛出预期的错_Asp.net_Sql Server_Smtpclient_Sqldatareader - Fatal编程技术网

Asp.net m、 Net.Mail.MailMessage“”不包含“密件抄送”的定义,并且找不到接受类型为的第一个参数的扩展方法“密件抄送”,并且在“SendMessage(MailMessage)”行错误6后出现一条红色扭曲线;预期,当我添加它时,它将抛出预期的错

Asp.net m、 Net.Mail.MailMessage“”不包含“密件抄送”的定义,并且找不到接受类型为的第一个参数的扩展方法“密件抄送”,并且在“SendMessage(MailMessage)”行错误6后出现一条红色扭曲线;预期,当我添加它时,它将抛出预期的错,asp.net,sql-server,smtpclient,sqldatareader,Asp.net,Sql Server,Smtpclient,Sqldatareader,m、 Net.Mail.MailMessage“”不包含“密件抄送”的定义,并且找不到接受类型为的第一个参数的扩展方法“密件抄送”,并且在“SendMessage(MailMessage)”行错误6后出现一条红色扭曲线;预期,当我添加它时,它将抛出预期的错误3},并在最后一个“}”错误4类型或命名空间定义后出现一条红色的曲线,或者预期的文件结尾是否可以测试。@Chuck抱歉,我的错误。应该是Bcc,而不是Bcc。一个快速的搜索会给你嘿,佐哈尔,我已经尝试过这个和其他各种东西,但仍然得到相同的错误


m、 Net.Mail.MailMessage“”不包含“密件抄送”的定义,并且找不到接受类型为的第一个参数的扩展方法“密件抄送”,并且在“SendMessage(MailMessage)”行错误6后出现一条红色扭曲线;预期,当我添加它时,它将抛出预期的错误3},并在最后一个“}”错误4类型或命名空间定义后出现一条红色的曲线,或者预期的文件结尾是否可以测试。@Chuck抱歉,我的错误。应该是
Bcc
,而不是
Bcc
。一个快速的搜索会给你嘿,佐哈尔,我已经尝试过这个和其他各种东西,但仍然得到相同的错误。请您尝试一下代码,如果您遇到相同的错误,请告诉我。我在
mailMessage.From=newmaildaddress(“myemail.com”)上遇到了一个异常
表示
“myemail.com”
不是有效的电子邮件地址格式。一旦我将所有的
“myemail.com”
更改为
”my@email.com“
我没有收到任何异常。嗨,Zohar,我修改了代码,它仍然只发送了一封电子邮件,没有异常。在这段代码中,我刚刚使用了myemail.com和smtp mail.myprovider.com。在我的代码中,我使用了正确的个人电子邮件和smtp语法,在供应商表中,我也使用了我的两个个人电子邮件地址。我只是不明白为什么不在表中循环并向两个电子邮件地址发送相同的电子邮件。
CREATE table Suppliers
(
    SuppId      INT IDENTITY(1,1)  PRIMARY KEY,
    SuppName    NVARCHAR(60)       NOT NULL, 
    SuppAddress NVARCHAR(150)      NOT NULL, 
    SuppSuburb  NVARCHAR(60)       NOT NULL, 
    SuppState   NVARCHAR(30)       NOT NULL, 
    SuppPost    NVARCHAR(10)       NOT NULL,
    SuppPhone   NVARCHAR(10)       NOT NULL,
    SuppEmail   NVARCHAR(100)      NOT NULL,
    SuppCode    NVARCHAR(10)       NOT NULL
)

Insert into Suppliers (SuppName, SuppAddress, SuppSuburb, SuppState, SuppPost, SuppPhone, SuppEmail, SuppCode) 
values ('Jacks Auto', '2 Jill Street', 'Belgrade', 'VIC', '3299', '9555 4457', 'frontdesk@jacksauto.com.au', 'JACBLA')

Insert into Suppliers (SuppName, SuppAddress, SuppSuburb, SuppState, SuppPost, SuppPhone, SuppEmail, SuppCode) 
values ('Ultimate Lights', '205 Browns Road', 'Tullamarine', 'VIC', '3011', '9877 2255', 'orders@ultimatlights.com.au', 'ULTTUL') 
  SqlDataReader sqlData;
  SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=SpecCars;Integrated Security=True");

  connection.Open();
  sqlData = new SqlCommand("Select SuppEmail From Suppliers", connection).ExecuteReader();

  int count = sqlData.FieldCount;

  while (sqlData.Read())
  {
     for (int i = 0; i < count; i++)
    {
      string emailnew = sqlData[i].ToString();

        MailMessage mailMessage = new MailMessage();

        mailMessage.From = new MailAddress("myemail.com");
        mailMessage.To.Add("myemail.com");
        mailMessage.To.Add(emailnew);
        //mailMessage.CC.Add(emailnew);
        mailMessage.Subject = "Assembly Line Stop";
        mailMessage.Priority = MailPriority.High;

        mailMessage.Body = "Please be advised that the assembly line at Specialised Cars has STOPPED. You will be notified once the line has started again. Any Services between the LINE STOP and the LINE START will be carried out after 19:00 (7pm).";
        mailMessage.IsBodyHtml = true;

        SmtpClient smtpClient = new SmtpClient("smtp-mail.myprovider.com", 587);
        smtpClient.EnableSsl = true;
        smtpClient.Credentials = new System.Net.NetworkCredential("myemail.com", "password");
        smtpClient.Send(mailMessage);
    }
}
connection.Close();
var mailMessage = CreateMessage();
using(var connection = new SqlConnection("Data Source=.;Initial Catalog=SpecCars;Integrated Security=True"))
{
    connection.Open();
    using(var sqlData = new SqlCommand("Select SuppEmail From Suppliers", connection).ExecuteReader())
    {
        while (sqlData.Read())
        {
            mailMessage.Bcc.Add(emailnew);
        }
    }
}
SendMessage(mailMessage)


private MailMessage CreateMessage()
{
    var mailMessage = new MailMessage();
    mailMessage.From = new MailAddress("myemail.com");
    mailMessage.To.Add("myemail.com");

    mailMessage.Subject = "Assembly Line Stop";
    mailMessage.Priority = MailPriority.High;

    mailMessage.Body = "Please be advised that the assembly line at Specialised Cars has STOPPED. You will be notified once the line has started again. Any Services between the LINE STOP and the LINE START will be carried out after 19:00 (7pm).";
    mailMessage.IsBodyHtml = true;
    return mailMessage;
}

private void SendMessage(MailMessage mailMessage)
{
    var smtpClient = new SmtpClient("smtp-mail.myprovider.com", 587);
    smtpClient.EnableSsl = true;
    smtpClient.Credentials = new System.Net.NetworkCredential("myemail.com", "password");
    smtpClient.Send(mailMessage);
}
 //-----------------

//Hi All, just a quick update:


//Trying8.aspx - Finally Works, it sends LINE STOP Email to every SuppEmail recipient in Suppliers Table

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Trying8.aspx.cs" Inherits="SpecCars.Admin.Trying8" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
      <br />
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

//-----------------

//Trying8.aspx.cs - Finally Works, it sends LINE STOP Email to every SuppEmail recipient in Suppliers Table

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace SpecCars.Admin
{
  public partial class Trying8 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {

      SqlDataReader sqlData;
      SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=SpecCars;Integrated Security=True");
      connection.Open();

      sqlData = new SqlCommand("Select * From Suppliers", connection).ExecuteReader();
      using (SmtpClient smtpClient = new SmtpClient("smtp-mail.provider.com", 587))
      {
        while (sqlData.Read())
        {
          string emailnew = sqlData["SuppEmail"].ToString();
          Label1.Text = emailnew.ToString();

          using (MailMessage message = new MailMessage())
          {
            try
            {
              message.From = new MailAddress("myemail@outlook.com");
              // This doesn't Send (To:) myotheremail@yahoo.com.au
              MailAddress AddressTo = new MailAddress("myotheremail@yahoo.com.au");
              // This does Send (To:) to SuppEmail recipient in Suppliers Table
              message.To.Add(emailnew);
              //This does Send a (CC:) myotheremail@yahoo.com.au
              message.CC.Add("myotheremail@yahoo.com.au");
              message.Subject = "Assembly Line Stop";
              message.Priority = MailPriority.High;

              message.Body = "Please be advised that the assembly line at Specialised Cars has STOPPED. You will be notified once the line has started again. Any Services between the LINE STOP and the LINE START will be carried out after 19:00 (7pm).";
              message.IsBodyHtml = true;

              smtpClient.EnableSsl = true;
              smtpClient.Credentials = new System.Net.NetworkCredential("myemail@outlook.com", "password");
              smtpClient.Send(message);
              // smtpClient.Dispose();
              // message.Dispose();
            }
            catch (Exception ex)
            {
              //log exceptions here, you can write it to a txt file, or to a label in your form for testing purpose
              //we are trying to see if you get an exception..
              Label1.Text = ex.Message;
            }
          }
        }
      }

    }
  }
}

//-----------------