ASP邮局:设置SMTP认证? [英] ASP WebMail: Set up SMTP authentication?

查看:235
本文介绍了ASP邮局:设置SMTP认证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用WebMatrix的剃刀C#语言的网页。我有一个托管网站,我试图将电子邮件系统到它。

I'm developing web pages using Razor C# language in WebMatrix. I have a hosted website, I'm trying to incorporate an email system into it.

根据这篇文章邮局我在_AppStart设立邮局设置.cshtml网页。我从我的服务提供商得到了我的设置。他使​​用CDO对象提供我一个样品code:

As per this article on WebMail I have set up the WebMail settings in my _AppStart.cshtml page. I've got my settings from my service provider. He's provided me a sample code using CDO object:

    dim config, sch     
    set config = CreateObject("CDO.Configuration")
    sch = "http://schemas.microsoft.com/cdo/configuration/"

    with config.Fields
        .item(sch & "sendusing") = 2 ' cdoSendUsingPort
        .item(sch & "smtpserver") = "myserver"
        .item(sch & "smtpserverport") = 25
        .item(sch & "smtpusessl") = False
        .item(sch & "smtpconnectiontimeout") = 60           
        .item(sch & "smtpauthenticate") = 1 'basic auth
        .item(sch & "sendusername") = "myemail@email.com"
        .item(sch & "sendpassword") = "password"
        .update
    end with

    Set myMail=CreateObject("CDO.Message")

    With myMail
        .Configuration = config
        .Subject = Request.Form("txtSubject")
        .From = Request.Form("txtFrom")
        .To = Request.Form("txtTo")
        .TextBody = Request.Form("txtMessage")
        Call .Send()
    End With    

正如你可以看到上面的code在CDO进行。我试图使用剃刀的邮局。在那里我坚持的唯一一点是,我的邮件服务器是不是SSL,但需要基本身份验证。我找不到任何的WebMail身份验证设置。如何设置在WebMail的SMTP认证?这是我目前的code:

As you can see the above code is made in CDO. I'm trying to use the WebMail in Razor. The only point where I'm stuck is that my email server is not SSL but requires basic auth. I can't find any authentication setting in WebMail. How do I set the SMTP authentication in WebMail? This is my current code:

WebMail.SmtpServer = "myserver";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "myemail@email.com";
WebMail.Password = "password";
WebMail.From = "Support <myemail@email.com>";

在此先感谢!

推荐答案

下面是在C#中一个基本的例子。在SMTP类需要的用户名密码。

Here's a basic example in c#. The Smtp class takes username password.

 MailMessage mail = new MailMessage("emailfrom","emailto");


        mail.From = new MailAddress("emailfrom");
        mail.Subject = txtsbjct.Text;
        string Body = txtmsg.Text;
        mail.Body = Body;

        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "localhost"; 
        smtp.Credentials = new System.Net.NetworkCredential
      ("youremail", "yourpassword");

这篇关于ASP邮局:设置SMTP认证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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