メール送信機能--自分でテストしました

1613 ワード

 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 = "zzzzz";// , [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);

            }