我正在使用WebMatrix中的剃刀C#语言开发网页。我有一个托管的网站,我正在尝试将一个电子邮件系统纳入其中。
根据this article on WebMail,我已经在我的_AppStart.cshtml页面中设置了WebMail设置。我已经从服务提供商那里获得了我的设置。他给我提供了一个使用CDO对象的示例代码:
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 如您所见,上面的代码是用CDO编写的。我正试着用剃刀里的WebMail我唯一被卡住的地方是我的电子邮件服务器不是SSL,但需要基本身份验证。我在WebMail中找不到任何身份验证设置。如何在WebMail中设置SMTP身份验证?这是我当前的代码:
WebMail.SmtpServer = "myserver";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "myemail@email.com";
WebMail.Password = "password";
WebMail.From = "Support <myemail@email.com>";提前感谢!
发布于 2012-09-18 00:01:04
这是一个用c#编写的基本示例。Smtp类接受用户名和密码。
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");发布于 2012-09-17 20:56:49
邮件服务器的基本身份验证通常包括提供用户名和密码。您可以使用WebMail.UserName和WebMail.Password属性来设置它们。
顺便说一句,您的提供商已经为您提供了在经典ASP中使用CDO发送邮件的示例代码。这对你没用。
https://stackoverflow.com/questions/12455383
复制相似问题