none
SL3 中通过RIAl service发送邮件失败,请高手帮忙分析! RRS feed

  • 问题

  • Service中的代码如下:

     // TODO: Create methods containing your application logic.
        [EnableClientAccess()]
        public class SendingMail : DomainService
        {
            public bool SendMail(string fromAddress, string toAddress, string subject, string body)
            {
                try
                {
                    MailMessage msg = new MailMessage();
                    msg.From = new MailAddress(fromAddress);
                    msg.To.Add(new MailAddress(toAddress));

                    msg.Subject = subject;
                    msg.Body = body;
                    msg.IsBodyHtml = true;

                    SmtpClient smtp = new SmtpClient();
                    smtp.Send(msg);

                    return true;

                }
                catch (Exception ex)
                {
                    return false;
                }          
            }
        }

    ***********************************************************************

    Client端的代码如下:

     bool isSendOK = false;

                SendingMail sm = new SendingMail();
                isSendOK = sm.SendMail("haokang1125@gmail.com", "haokang1125@gmail.com", "this is a test", "what's going on?").Value;
                if (isSendOK)
                {
                    MessageBox.Show("OK");
                }
                else
                {
                    MessageBox.Show("Failed");
                }

    ***********************************************************************

    Web.config的配置如下:

    <system.net>
        <mailSettings>
          <smtp>
            <network host="smtp.gmail.com" port ="587" userName="haokang1125@gmail.com" password="isTesting11"/>
          </smtp>
        </mailSettings>
      </system.net>

    在执行client端的代码时总是返回false,请问怎么解决?

    谢谢先!

    2010年5月10日 7:23

答案

全部回复