English 中文(简体)
NET Bestmeth to Send Email (System). 邮局
原标题:
  • 时间:2009-05-30 18:07:31
  •  标签:

这似乎很简单。 我需要从一些伙伴关系发送电子邮件。 NET应用软件。 我需要始终如一地这样做,不出现奇怪的错误,也不需要使用万国邮联。 我不谈大规模电子邮件,只是偶尔的电子邮件。

系统.Net.mail appears to be horriblytter. SmtpClient没有发出基特指挥(可能是因为微软(R)不有兴趣遵守规格),因此,连接没有开放。 因此,如果有人试图在连接之前进行电子邮件,即最终关闭,你就能够从员工和管理当局协调署服务器获得太多的连接线上的错误。 这是Microsoft(R)在固定时完全没有兴趣的ug。 见下文:

另外,如果你看一看某些人建议使用该守则解决这一问题:

smtpClient.ServicePoint.MaxIdleTime = 1;
smtpClient.ServicePoint.ConnectionLimit = 1;

Ok, 是,“解决”连接问题不开放。 然而,如果你愿意,这始终在服务器上尝试,就会使邮联(在这种情况下,总价为3wp.exe)能够跳跃,并且保持100%,直到您的申请库回收为止。 无论出于何种原因, runs子的read! 造物是主。

这具有非常明显的副作用,即如果你在网络主机上运行,连续使用100%的加拿大邮联,你就会有残疾。 因此,这并不像一些人所建议的那样微不足道。

因此,我的问题是什么? 我需要做的是这样简单的事情;然而,将“许多链接打开”错误带给这些错误是不能接受的,也是不能接受的,也是不能接受的。 我不想购买第三方部分,并不是因为I m便宜,而是因为我购买足够的部件和MSDN订阅,即似乎必须支付100-300美元的简单员工和管理当局协调会功能。

我读到,把马克斯·埃克斯时代的较高者确定下来,可以帮助,但我对此持怀疑态度。 我不想冒着我的人才库残疾的风险,因为微软不想遵守员工和管理当局协调会的具体规定。

<><>Edit>: 我审视了静电软.com部分,但是它不支持员工和管理当局协调会的认证,它花费500美元。 这个问题必须得到解决。

最佳回答

我在所述环境中也面临着同样的使用万国邮联的问题。 我最后向微软开张,以确定问题的原因。 万国邮联的利用问题在于服务点类别。 在内部,在服务点班中,有一台运行时间(MaxItime/2)毫米秒。 见问题? 将马克斯时值改为2,万国邮联的利用率将降至正常水平。

问题回答

在NET 4.0中,SmtpClient现在可以放弃。 员工和管理当局协调小组的装备在处置时,如在使用部件时使用。

我们利用hmailserver,取得了巨大成功。 配置可以同时使用,但这是一个巨大的——免费——邮件服务器产品。

如果你想推出你自己的话(我几年前在裁谈会拥有一个时间),你可以开始采用以下守则,并符合你的心脏内容。 它利用TcpClient直接与邮件服务器建立TCP联系。 如果存在如此多的固定和破碎的解决办法,我不建议这样做,但我发现,这非常有助于清醒和确定问题涉及预定的邮件部分。

    private void Send_Email() 
    {
        #region Email Sending Function
        string strMail = "";

        try 
        {
            // See RFC821 http://www.faqs.org/rfcs/rfc821.html for more specs
            // TcpClient is an abstraction of a TCP Socket connection
            TcpClient myTCP = new TcpClient();

            // Connect to the mail server s port 25
            myTCP.Connect(mailserver, 25);

            // Open a network stream which sends data to/from the TcpClient s socket
            System.Net.Sockets.NetworkStream ns = myTCP.GetStream();

            // The data to send to the mail server, basically a raw SMTP mail message
            strMail = "HELO
";
            strMail += "MAIL FROM:from@address.com
";
            strMail += "RCPT TO:" + recipient + "
";
            strMail += "DATA
";
            strMail += "Subject: mySubject
";
            strMail += "To:" + recipient + "
";
            strMail += "From: "From Real Name" <from@address.com>
";
            strMail += "
";
            strMail += " ---------------------------------------
";
            strMail += "Name:     " + txtName.Text + "
";
            strMail += "Address1: " + txtAddress1.Text + "
";
            strMail += "Address2: " + txtAddress2.Text + "
";
            strMail += "City:     " + txtCity.Text + "
";
            strMail += "State:    " + txtState.Text + "
";
            strMail += "Zip:      " + txtZip.Text + "
";
            strMail += "Email:    " + txtEmail.Text + "
";
            strMail += "Dealer:   " + txtDealer.Text + "
";
            strMail += " ---------------------------------------
";
            strMail += "THIS IS AN AUTOMATED EMAIL SYSTEM. DO NOT REPLY TO THIS ADDRESS.
";
            strMail += "
.
";

            // Defines encoding of string into Bytes (network stream needs
            // an array of bytes to send -- can t send strings)
            ASCIIEncoding AE = new ASCIIEncoding();
            byte[] ByteArray = AE.GetBytes(strMail);

            // send the byte-encoded string to the networkstream -> mail server:25
            ns.Write(ByteArray, 0, ByteArray.Length);

            //ns.Read(ByteArray, 0, ByteArray.Length);
            //lblStatus.Text = ByteArray.ToString();

            // close the network stream
            ns.Close();

            // close the TCP connection
            myTCP.Close();
        }
        catch(Exception ex) 
        {
            throw new Exception("Couldn t send email: <p>" + ex.Message);
        }

        #endregion

    }

虽然迄今为止,我有tn t在System.Net.mail上存在任何具体问题,但你可以始终使用System.Web. 。 内容提要

我过去曾使用Quicksoft,没有抱怨。 你们可以尝试的另一件事情是把员工和管理当局协调会的组合换成使用一组子,而不是利用网络发送,而网络应围绕“它不会寄送设备”。

我用Sproc寄来大多数邮件。 我甚至可以附上一份档案。


CREATE PROCEDURE [dbo].[sendMail_With_CDOMessage]  
    @to VARCHAR(64), 
    @CC VARCHAR(1024)=  ,
    @BCC VARCHAR(1024)=  ,
    @subject VARCHAR(500)=  , 
    @body VARCHAR(8000)=   ,
    @from VARCHAR(64),
    @filename VARCHAR(255)=  ,
    @priority INT = 0
AS  
BEGIN  
    SET NOCOUNT ON  

    DECLARE  
        @handle INT,  
        @return INT,  
        @s VARCHAR(64),  
        @sc VARCHAR(1024),  
        @up CHAR(27),   
        @server VARCHAR(255)  

    SET @s =  "http://schemas.microsoft.com/cdo/configuration/   

    SELECT  
        @s =  Configuration.Fields(  + @s,  
        @up =  Configuration.Fields.Update ,
        @server =  smtp.yourdomain.com  



    EXEC @return = sp_OACreate  CDO.Message , @handle OUT  
    SET @sc = @s +  sendusing").Value   
    EXEC @return = sp_OASetProperty @handle, @sc,  2   
    SET @sc = @s +  smtpserver").Value   
    EXEC @return = sp_OASetProperty @handle, @sc, @server  
    EXEC @return = sp_OAMethod @handle, @up, NULL  
    EXEC @return = sp_OASetProperty @handle,  To , @to  
    EXEC @return = sp_OASetProperty @handle,  CC , @CC 
    EXEC @return = sp_OASetProperty @handle,  BCC , @BCC 
    EXEC @return = sp_OASetProperty @handle,  From , @from  
    EXEC @return = sp_OASetProperty @handle,  Subject , @subject  
    EXEC @return = sp_OASetProperty @handle,  HTMLBody , @body    
    EXEC @return = sp_OASetProperty @handle,  Priority ,  cdoHigh   

    IF @filename IS NOT NULL  
        EXEC @return = sp_OAMethod @handle,  AddAttachment , NULL, @filename  

    EXEC @return = sp_OAMethod @handle,  Send , NULL  
    IF @return  0  
    BEGIN  
        PRINT  Mail failed.   
        IF @from IS NULL  
            PRINT  From address undefined.   
        ELSE  
            PRINT  Check that server is valid.  
    END 
    ELSE  
        PRINT  Mail sent.   

    EXEC @return = sp_OADestroy @handle  
END  





相关问题
热门标签