为什么我不能从本地和服务器两边发送邮件 [英] Why i can't send mail from local and server both side
本文介绍了为什么我不能从本地和服务器两边发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码发送邮件,
var smtp = new System.Net.Mail.SmtpClient();
{
// smtp.Host =smtp.gmail.com;
// smtp.Port = 587;
// smtp.EnableSsl = true;
smtp.Host = localhost;
smtp.Port = 25 ;
smtp.EnableSsl = false ;
smtp.UseDefaultCredentials = false ;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromMail.ToString(), 2345664\" 跨度>);
smtp.Timeout = 20000 ;
}
smtp.Send(Msg);
reader.Dispose();
使用此方法我无法从本地和服务器端发送邮件。
i得到了这个错误 - 当我在localhost上运行我的代码时
由于目标机器主动拒绝它,因此无法建立连接127.0.0.1 :25
但我也可以从服务器端发送邮件。
谁能告诉我原因为此,并为此提供解决方案。?
解决方案
检查此链接
http://stackoverflow.com/questions/15462960/can- we-send-mails-from-localhost-using-asp-net-and-c [ ^ ]
http://stackoverflow.com/questions/10205268/sending-emails-from-localhost-and-online-asp-net [< a href =http://stackoverflow.com/questions/10205268/sending-emails-from-localhost-and-online-asp-nettarget =_ blanktitle =New Window> ^ ]
http://stackoverflow.com/questions/18803600/how-to-send-mail-using-localhost-and-from-asp-net- website-i-cant-get-the-smtp-t [ ^ ]
希望这些对你有用...
非常感谢你提供解决方案,
现在我用这个发送邮件的代码,
protected void getDataforemail( int invitationID)
{
try
{
EventManagerDataContext db = new EventManagerDataContext();
{
var q =(来自 a db.EMR_EVENTs
join b a.ClientID上的db.EMR_CLIENTs等于b.ClientID
join c db.EMR_INVITATIONs on a.EventID等于c.EventID
其中 c.InvitationID == invitationID
选择 new
{
EventID = a.EventID,
Client_Name = b.Name,
Event_Name = a.Name,
Activation_Code = c.Activation_Code
});
var ev = q.FirstOrDefault();
StreamReader reader = new StreamReader(Server.MapPath( 〜/ HTMLPage1.htm跨度>));
string readFile = reader.ReadToEnd();
string myString = ;
myString = readFile;
MailAddress fromMail = new MailAddress( ketanitaliya16@gmail.com);
Msg.CC.Add( new MailAddress(clientEmail(getClientId(lblclientname.Text))));
myString = myString.Replace(
>
CLIENT_NAME
I use this code for send mail ,
var smtp = new System.Net.Mail.SmtpClient();
{
//smtp.Host = "smtp.gmail.com";
//smtp.Port = 587;
//smtp.EnableSsl = true;
smtp.Host = "localhost";
smtp.Port = 25;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromMail.ToString(), "2345664");
smtp.Timeout = 20000;
}
smtp.Send(Msg);
reader.Dispose();
using this method i can't send mail,from both local and server side.
i got this error -when i run my code on localhost
No connection could be made because the target machine actively refused it 127.0.0.1:25
but i also enable to send mail from server side.
can anyone tell me reason for that,and give solution for that.?
解决方案
check this links
http://stackoverflow.com/questions/15462960/can-we-send-mails-from-localhost-using-asp-net-and-c[^]
http://stackoverflow.com/questions/10205268/sending-emails-from-localhost-and-online-asp-net[^]
http://stackoverflow.com/questions/18803600/how-to-send-mail-using-localhost-and-from-asp-net-website-i-cant-get-the-smtp-t[^]
Hope these are useful for you...
Thanks a lot for giving solution,
now i use this code for sending mail,
protected void getDataforemail(int invitationID) { try { EventManagerDataContext db = new EventManagerDataContext(); { var q = (from a in db.EMR_EVENTs join b in db.EMR_CLIENTs on a.ClientID equals b.ClientID join c in db.EMR_INVITATIONs on a.EventID equals c.EventID where c.InvitationID == invitationID select new { EventID = a.EventID, Client_Name = b.Name, Event_Name = a.Name, Activation_Code = c.Activation_Code }); var ev = q.FirstOrDefault(); StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage1.htm")); string readFile = reader.ReadToEnd(); string myString = ""; myString = readFile; MailAddress fromMail = new MailAddress("ketanitaliya16@gmail.com"); Msg.CC.Add(new MailAddress(clientEmail(getClientId(lblclientname.Text)))); myString = myString.Replace("
Client_Name
这篇关于为什么我不能从本地和服务器两边发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文