为什么不发送电子邮件 [英] Why don't send email

查看:134
本文介绍了为什么不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Paypal notifyback将在我的控制器中触发我的mehed时。

是的方法确实是触发器,除了发送电子邮件功能不起作用



When Paypal notifyback will trigger my methed in my controller.
Yes the method is indeed trigger, And except the send email function don't work

if (amountPaid == price)
               {
                   if (payment_status.ToLower() == &completed)
                   {
                       //update the database table function over there 
                       //it works
                      //Send Parse Email to company  system                    

                        SendParseEmail(clientID);//this didn't work
////send a comfirmation email withe QR code
                        ////send email to the client
                       
                            SendClientEmail(clientID);
                       }
               ///follow code all working correcting
//....


  public void SendParseEmail(int clientID)
        {
            //there are a lot of code just for get information from database               

                     var mailMessage = new MailMessage();
                     mailMessage.From = new MailAddress("xxxx@xxx.xxx");
                     mailMessage.To.Add("xxx@xxx.xxx");// 

                     mailMessage.Body = mm_Form.ToString();
                     mailMessage.IsBodyHtml = false;
                
                 
                 Thread parseEmail = new Thread(delegate()
                 {
                     var mysmtpParse = new SmtpClient();
                     mysmtpParse.Send(mailMessage);
                 });
                 parseEmail.IsBackground = true;
                 parseEmail.Start();

             }
        }

 public void SendClientEmail(int clientID)
        {
            string fileName = Server.MapPath("~/Common/ClientEmail.html");
            string mailBody = System.IO.File.ReadAllText(fileName);
            if(book.ContactName==null)
                mailBody = mailBody.Replace("##ContactName##", book.UserName);
            else
                mailBody = mailBody.Replace("##ContactName##", book.ContactName);
            mailBody = mailBody.Replace("##Email##", book.Email);
            if(book.Phone2==null)
                mailBody = mailBody.Replace("##HomePhone##", book.Phone);
            else
                mailBody = mailBody.Replace("##HomePhone##", book.Phone2);
            mailBody = mailBody.Replace("##Pickup##", PickupInfo);
            mailBody = mailBody.Replace("##Destination##", DropoffInfo);
            mailBody = mailBody.Replace("##Vehicle##", "Shuttle");
            mailBody = mailBody.Replace("##numAdults##", numOfPaxStr);
            mailBody = mailBody.Replace("##UnitAdultPrice##", unitOfPriceStr);            
            mailBody = mailBody.Replace("##TotalPrice##", totalPrice);
            mailBody = mailBody.Replace("##PaidDate##", paidDay); 
            mailBody = mailBody.Replace("##PaidAmount##", amountPaid.ToString()); 


            var myMessage = new MailMessage();

            myMessage.Subject = "Shuttle Booking:" + book.Ref + "(" + cityName + "): Tax Invoice, Travel Details & Receipt";
            myMessage.Body =  mailBody;
            myMessage.IsBodyHtml = true;

            myMessage.From = new MailAddress("xxx@xxx.xxx", "Royale Airport Transfer Bookings");//enquiries@royalecoach.com.au
            myMessage.To.Add(new MailAddress(payer_email, userName));
            
           
            Thread clientEmail = new Thread(delegate()
            {
                var mysmtpClient = new SmtpClient();
                mysmtpClient.Send(myMessage);
            });
            clientEmail.IsBackground = true;
            clientEmail.Start();

        }

推荐答案

你可能无处发送它。您使用的 SmtpClient 构造函数基于您通过编写适当的配置文件选择SMTP服务器和所有参数的假设:

http://msdn.microsoft.com/en-us/library/k1c4h6e2%28v = vs.110%29.aspx [ ^ ]。



谁知道你在配置文件中写了什么,如果它甚至存在? :-)



要使用端口明确选择服务器或服务器,您需要使用其他构造函数:

http://msdn.microsoft.com/en-us/library/k0y6s613(v=vs .110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/67w4as51(v = vs.110).aspx [ ^ ]。



此外,如果一切都完成,我不能确定您使用正确的服务器和身份验证参数。你可以这样做:尝试使用一些可用的邮件客户端程序服务器,当你确定它真的发送消息时,模仿代码中的所有参数。



-SA
It's possible that you are sending it nowhere. The SmtpClient constructor you are using is based on assumption that you chose you SMTP server and all the parameter by writing appropriate configuration file:
http://msdn.microsoft.com/en-us/library/k1c4h6e2%28v=vs.110%29.aspx[^].

Who knows what did you write in that configuration file, if it even exists? :-)

To explicitly choose the server or server with the port, you would need to use other constructors:
http://msdn.microsoft.com/en-us/library/k0y6s613(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/67w4as51(v=vs.110).aspx[^].

Besides, if everything is done, I cannot be sure that you used correct parameters for the server and authentication. You can do this: try the server you have with some available mail client program, and when you make sure it really sends messages, mimic all the parameters in your code.

—SA


我自己已经解决了,我有一些参数不正确
It has been sovled by myself, I have some parameter is not correct


这篇关于为什么不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆