asp.Net送信メールコード(Gmail、163送信可能)

4950 ワード

今日gmailのメールボックスをテストして送ることができて、その他の私はテストして送ることができません.
#regionメールを送信する関数/////メールを送信する関数Gmail/////メールテーマ//メール内容//メールボックスサーバ(空の値はsmtp.gmail.com)//「受信メールボックス///「送信者メールボックス///「送信者メールボックスパスワード///「送信者メールボックス名//「送信者メールポートを表示」(デフォルトは587)///戻りプロンプトpublic static string SendEmailG(string EmailSubject,string EmailBody,string smtpserver,string receiveEmail,string FromEmail,string FromPassword,string FromEmailName,params int[]SmtpPort){try{FromEmailName=(FromEmailName="?システム発行":FromEmailName);                smtpserver = (smtpserver == ""? "smtp.gmail.com": smtpserver);                 System.Net.Mail.MailMessage mailObj = new System.Net.Mail.MailMessage();                 mailObj.IsBodyHtml = true;                 mailObj.Subject = EmailSubject;                 mailObj.Body = EmailBody;                 mailObj.To.Add(new MailAddress(receiveEmail, receiveEmail, System.Text.Encoding.UTF8));                 mailObj.BodyEncoding = System.Text.Encoding.UTF8;                 mailObj.SubjectEncoding=System.Text.Encoding.UTF8;                 System.Net.Mail.SmtpClient SmtpMail = new SmtpClient(smtpserver);                 mailObj.From = new MailAddress(FromEmail, FromEmailName, System.Text.Encoding.UTF8);                 SmtpMail.Credentials = new System.Net.NetworkCredential(FromEmail, FromPassword);//gmail独自構成開始SmtpMail.Port =(SmtpPort.Length<=0?587:SmtpPort[0]);                 SmtpMail.EnableSsl = true;//gmail固有構成完了SmtpMail.Send(mailObj); return「送信成功!」;            }             catch (Exception ex)             {                 return ex.ToString();             }         }         #endregion
 
//163メールボックスの送信可能
        string ErrMsg = "";

        public Email()
        {

        }

        /// <summary>
        ///     
        /// </summary>
        /// <param name="smtpserver">     </param>
        /// <param name="mailuser">    </param>
        /// <param name="mailpassword">    </param>
        /// <param name="mailFrom">   </param>
        /// <param name="mailContent">    </param>
        /// <param name="mailTo">    </param>
        /// <param name="mailTitle">    </param>
        /// <returns></returns>
        public bool SendEmail(string smtpserver, string mailuser, string mailpassword, string mailFrom, string mailContent, string mailTo, string mailTitle)
        {
            MailMessage mail = new MailMessage(mailFrom, mailTo);
            mail.BodyEncoding = Encoding.Default;
            mail.Subject = mailTitle;
            mail.Body = mailContent;
            mail.Priority = MailPriority.Normal;
            mail.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient(smtpserver);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential(mailuser, mailpassword);
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                smtp.Send(mail);
                mail.Dispose();//    
                smtp.Dispose();//    
            }
            catch (Exception ex)
            {
                ErrMsg = ex.Message;
                return false;
            }
            return true;
        }
        /// <summary>
        ///     
        /// </summary>
        /// <param name="config">    config  </param>
        /// <param name="mailContent">    </param>
        /// <param name="mailTo">    </param>
        /// <param name="mailTitle">    </param>
        /// <returns></returns>
        public bool SendEmail(DataRow config, string mailContent, string mailTo, string mailTitle)
        {
            string MailSmtpServer = config["MailSmtpServer"].ToString();
            string MailServerUserName = config["MailServerUserName"].ToString();
            string MailServerPassWord = config["MailServerPassWord"].ToString();
            string MailServerFrom = config["MailServerFrom"].ToString();
            return SendEmail(MailSmtpServer, MailServerUserName, MailServerPassWord, MailServerFrom, mailContent, mailTo, mailTitle);
        }
        //<MailSmtpServer>smtp.163.com</MailSmtpServer>
        //<MailServerUserName>[email protected]</MailServerUserName>
        //<MailServerPassWord>*****</MailServerPassWord>
        //<MailServerFrom>[email protected]</MailServerFrom>

-----pukuimin