How to send e-mail from asp using gmail?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Sending email in .NET through Gmail
How do you send email from a Java app using Gmail?
号
在这里,我尝试从我的ASP应用程序发送电子邮件警报。大多数人都说,使用SQL Server的邮件功能发送电子邮件非常容易。但不幸的是,我目前正在运行SQL Server 2008 Express Edition,它没有邮件功能。请有人帮我用G-mail发电子邮件。
这可能有助于您开始:
1 2 3 4 5 6 7 8 9 | 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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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); |
我想这对你有帮助
您可以安装一个SMTP服务器并运行它
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [ASP] <% Set oSmtp = Server.CreateObject("AOSMTP.Mail") oSmtp.ServerAddr ="127.0.0.1" oSmtp.FromAddr ="[email protected]" oSmtp.AddRecipient"name","[email protected]", 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服务器,或者访问允许远程连接的服务器(通过中继或名称/密码身份验证)。
试试这个
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | using System.Net.Mail; using System.Net; var fromAddress = new MailAddress("[email protected]","From Name"); var toAddress = new MailAddress("[email protected]","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); } |
。