可能重复:
Sending email in .NET through Gmail
How do you send email from a Java app using Gmail?
这里我正在尝试从我的asp应用程序发送电子邮件警报。大多数人说使用SQL服务器的邮件功能发送电子邮件非常容易。但不幸的是,我目前正在运行SQL Server 2008 Express版,它没有邮件设施。请任何人帮我用邮件发送电子邮件。
答案 0 :(得分:2)
这可能有助于您开始:
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Subject";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("FromEmailId", "Name");
myMessage.To.Add(new MailAddress("ToEmailId", "Name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
答案 1 :(得分:1)
您可以安装SMTP服务器并运行此
[ASP]
<%
Set oSmtp = Server.CreateObject("AOSMTP.Mail")
oSmtp.ServerAddr = "127.0.0.1"
oSmtp.FromAddr = "from@yourdomain.com"
oSmtp.AddRecipient "name", "to@domain2.com", 0
oSmtp.Subject = "your subject"
oSmtp.BodyText = "your email body"
If oSmtp.SendMail() = 0 Then
Response.Write "OK"
Else
Response.Write oSmtp.GetLastErrDescription()
End If
%>
以上是ASP *你说ASP。如果您使用的是asp.net,请使用Rajpurohit的示例代码,但您需要安装smtp服务器,或者可以访问允许远程连接的服务器(通过中继或名称/密码身份验证)
答案 2 :(得分:1)
电子邮件发送代码: -
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
// When You use a Gmail Hosting then u You write Host name is smtp.gmail.com.
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.Credentials = new System.Net. NetworkCredential("YourHost@UserName","Password");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("fromAddress");
msg.To.Add("ToAddress");
msg.Subject = "Subject";
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.body="body";
client.Send(message);
我认为这会对你有所帮助
答案 3 :(得分:0)
试试这个
using System.Net.Mail;
using System.Net;
var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@gmail.com", "To Name");
const string fromPassword = "password";
const string subject = "test";
const string body = "Hey now!!";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}