-1

可能重复:
通过 Gmail 在 .NET 中发送电子邮件
如何使用 Gmail 从 Java 应用程序发送电子邮件?

在这里,我试图从我的 asp 应用程序发送电子邮件警报。大多数人都说使用 SQL Server 的邮件功能发送电子邮件非常容易。但不幸的是,我目前正在运行 SQL Server 2008 Express 版本并且它没有邮件功能。请任何人帮助我使用 g-mail 发送电子邮件。

4

4 回答 4

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);
于 2012-10-03T04:33:14.460 回答
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 服务器,或者可以访问允许远程连接的服务器(通过中继或名称/密码验证)

于 2012-10-03T04:42:23.240 回答
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);

我想这会对你有所帮助

于 2012-10-03T04:57:14.423 回答
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);
            }
于 2012-10-03T06:51:58.180 回答