c calls qq mailbox smtp to send a message modified version of code sharing

  • 2020-05-27 06:58:55
  • OfStack


 try
            {
                MailMessage mm = new MailMessage();
                MailAddress Fromma = new MailAddress("xxxx@qq.com");
                MailAddress Toma = new MailAddress("MMMMMMM@qq.com", null);
                mm.From = Fromma;
                // The recipient 
                mm.To.Add("MMMMMM@qq.com");
                // Your email title 
                mm.Subject = "Hello Dear:";
                mm.IsBodyHtml = true;
                // Email content 
                mm.Body = " hello Mr Shooting stars! ";
                // The encoding format of the content 
                mm.BodyEncoding = System.Text.Encoding.UTF8;
                //mm.ReplyTo = Toma;
                //mm.Sender =Fromma;
                //mm.IsBodyHtml = false;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                mm.CC.Add(Toma);
                SmtpClient sc = new SmtpClient();
                NetworkCredential nc = new NetworkCredential();
                nc.UserName = "XXXXX@qq.com";// Your email address 
                nc.Password = "zzzzz";// Your email password , The password here is xxxxx@qq.com The password of the mailbox, special explanation below ~
                   sc.UseDefaultCredentials = true;
                sc.DeliveryMethod = SmtpDeliveryMethod.Network;
                sc.Credentials = nc;
                // If I quote here mail from address must be same as authorization user The mistake is yours QQ The mailbox is not open SMTP . 
                // Go to your own mailbox Settings 1 Next can! Under the account , If it is 163 Email, the following should be smtp.163.com
                sc.Host = "smtp.qq.com";
                sc.Send(mm);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

This is what I have successfully tested with my two QQ tests. Please correct me if you have any questions


Related articles: