asp c#中的smtp设置? [英] smtp setting in asp c# ?

查看:112
本文介绍了asp c#中的smtp设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

i使用此代码使用asp和c发送电子邮件#

hi all
i use this code to send email using asp and c#

 SmtpClient client = new SmtpClient(???);
 MailMessage mailMessage = new MailMessage();
 mailMessage.From = new MailAddress("senderEmail");
 mailMessage.To.Add("ToEmail");

 mailMessage.Subject = "hi";
 mailMessage.Body = "message";
 mailMessage.IsBodyHtml = true;
client.Send(mailMessage);



但是我可以使用任何smtp客户端值吗?

i需要公开吗?

我可以在我当地的主机pc和服务器托管中使用它

请帮助我:)


but are there any smtp client value can i use it ?
i need it public ?
that i can use it in my local host pc and server hosting
please help me :)

推荐答案

所以你需要一个SMTP服务器传递给控制器​​吗?

嗯,这取决于。例如,您可以使用Gmail,但您可能会遇到限制 [ ^ ]。它可以用于测试。以下是从代码中使用它的方法: http://www.dustinhorne。 com / post /发送 - 使用Google-Mail-and-ASPNET发送电子邮件 [ ^ ]



对于托管生产环境,您应该咨询服务提供商的网站页面或联系他们。他们也可以告诉你参数和限制。
So you need an SMTP server do pass to the controller?
Well, it depends. You can use gmail for example but youm ight encounter limitations[^]. It will be just fine for testing. Here is how you can use it from code: http://www.dustinhorne.com/post/Sending-Email-With-Google-Mail-and-ASPNET[^]

For a hosted production environment, you should consult your service provider's web page or contact them. They can tell you the parameters and the limitations also.


在给你一个解决方案之前,让我介绍一下。由于您使用的是ASP.NET,为什么使用.NET方式发送电子邮件。 ASP.NET有自己的发送电子邮件的方法,这使得在ASP.NET中发送电子邮件对开发人员来说简单而有效。



您可以阅读我在这篇文章中发送的电子邮件:轻松使用ASP.NET助手发送电子邮件 [ ^ ]



其次,有许多服务器可用于将电子邮件发送给客户端。 Gmail,Outlook或Yahoo都是免费服务提供商的例子,可以从托管环境到测试环境使用,它可以在两者中使用。我个人总是使用Gmail服务器,虽然我有Outlook和雅虎帐户。您还应该使用这些服务器,它们将为您服务。设置环境以发送电子邮件的示例代码可以是这样的,



Let me intervene here before giving you a solution. Since you're using ASP.NET, why are you using the .NET way of sending the emails. ASP.NET has their own method of sending emails, which makes sending emails in ASP.NET a bit easy and efficient for the developers.

You can read on sending the emails in ASP.NET from my article here: Sending Emails Easily Using ASP.NET Helpers[^]

Secondly, there are many servers that can be used to send the emails to clients. Gmail, Outlook or Yahoo all are the examples of free service providers, which can be used from hosting environment to testing environment and it works in both. I have personally always used the Gmail servers, although I do have Outlook and Yahoo accounts. You should also use these servers and they will work for you. An example code for setting up the environment to send email can be like this one,

// basic settings...
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.UserName = "<youremail@theirserver.com>";
WebMail.Password = "yourpassword";
WebMail.From = "SendersEmail@client.com";
// these are required for these remote servers
WebMail.SmtpPort = 25;
WebMail.EnableSsl = true;





..然后发送电子邮件代码就是这个,





.. then sending the email code is as this one,

WebMail.Send(to: "recipient@example.com",
             subject: "hi",
             body: "message");





..这将使用上面提供的设置发送电子邮件。与.NET框架中提供的MailMessage和SmtpClient类相比,这非常简单,因为您还需要使用NetworkCredentials和其他此类设置。



.. this would send the email, using above provided settings. This is pretty much easy, as compared to the MailMessage and the SmtpClient class provided in the .NET framework, as you're required to work with NetworkCredentials and other such setup too.


我们有与google,hotmail和yahoo链接的smtp服务器可以使用
We have smtp servers linked with google, hotmail and yahoo which can be used


这篇关于asp c#中的smtp设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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