標籤:
public static void QQfs() { try { MailMessage mm = new MailMessage(); MailAddress Fromma = new MailAddress("[email protected]"); MailAddress Toma = new MailAddress("[email protected]", null); mm.From = Fromma; //收件者 mm.To.Add("[email protected]"); //郵箱標題 mm.Subject = "Hello Dear:"; mm.IsBodyHtml = true; //郵件內容 mm.Body = "你好Mr流星!"; //內容的編碼格式 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 = "[email protected]";//你的郵箱地址 nc.Password = "xxxxxxxx";//郵箱密碼,這裡的密碼是[email protected]郵箱的密碼~ sc.UseDefaultCredentials = true; sc.DeliveryMethod = SmtpDeliveryMethod.Network; sc.Credentials = nc; //如果這裡報mail from address must be same as authorization user這個錯誤,是你的QQ郵箱沒有開啟SMTP, //到你自己的郵箱設定一下就可以啦!在帳戶下面,如果是163郵箱的話,下面該成smtp.163.com sc.Host = "smtp.qq.com"; sc.Send(mm); } catch (Exception ex) { throw new Exception(ex.Message); } }
C# .net 調用QQ郵箱