开发者

asp.net send email using gmail on local machine

I am using gmail in my asp.net site to send email. It is working fine on shared server but it donot send email when I run my site on local machine in visual studio. Please guide what should I do开发者_开发技巧 to make it sending emails from local machine as well.

thanks

below is my code:

 dt = systemrep.GetSystemInfo();
                dr = dt.Rows[0];
                From = dr["nm_EmailFrom"].ToString();
                SMTP = dr["nm_SMTP"].ToString();
                Port = dr["amt_Port"].ToString();
                EmailId = dr["nm_emailUserId"].ToString();
                EmailPassword = dr["nm_emailPassword"].ToString();
                DefaultCredations = Convert.ToBoolean(dr["ind_Credentials"].ToString());
                MailMessage message = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                NetworkCredential mailAuthentication = new NetworkCredential(EmailId, EmailPassword);
                message.To.Add(new MailAddress(email.To));
                message.From = new MailAddress(From);
                message.IsBodyHtml = true;
                message.Subject = email.Subject;
                message.Body = email.Message;
                smtp.UseDefaultCredentials = DefaultCredations;
                smtp.EnableSsl = true;
                smtp.Port = 587;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Host = SMTP;
                smtp.Credentials = new NetworkCredential(EmailId, EmailPassword);


                smtp.Send(message);


What are you using as your SMTP server? If you are using localhost (which may work on the server), it probably won't work on your local machine.


If you're sending via smtp.gmail.com from your server OK, but the same code doesn't work on your local machine, it's probably a firewall or antivirus problem.

From your local machine, try "telnet smtp.gmail.com 25" and see if you can connect.

Try disabling the firewall and/or antivirus and see if that fixes the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜