c USES netmail to send mail samples

  • 2020-06-07 05:10:26
  • OfStack


/// <summary>
    /// NetMail Mode test passed 
    /// </summary>
    private void TestSend()
    {
        System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
        // Recipient address 
        mm.To.Add(new System.Net.Mail.MailAddress("xxxxxx@163.com", "Name"));
        // Sender address 
        mm.From = new System.Net.Mail.MailAddress("xxxxx@sina.com");
        // This can be left unspecified 
        //mm.Sender = new System.Net.Mail.MailAddress("xxx@sina.com", "SenderName"); , 
        mm.Subject = "This is Test Email";
        mm.Body = "<h3>This is Testing SMTP Mail Send By Me</h3>";
        mm.IsBodyHtml = true;
        mm.Priority = System.Net.Mail.MailPriority.High; //  Set the priority of sending messages 
        System.Net.Mail.SmtpClient smtCliend = new System.Net.Mail.SmtpClient();
        // Specify mail server 
        smtCliend.Host = "smtp.sina.com";
        //smtp The port number of the mail server   
        smtCliend.Port = 25;   
        // Set the user name and address of the sender's mailbox, using the public mail server 1 Generally need to provide, otherwise the send will not succeed 
        smtCliend.Credentials = new NetworkCredential("xxxxxxx", "xxxxxxx");
        // Specifies how the message should be sent 
        smtCliend.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        try
        {
            smtCliend.Send(mm);
        }
        catch (System.Net.Mail.SmtpException ex)
        {
            Response.Write(ex.Message);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }


Related articles: