-1

Possible Duplicate:
Sending email in .NET through Gmail
How do you send email from a Java app using Gmail?

Here I'm trying to send an e-mail alert from my asp application. Most of the people said that it is very easy to send e mail using SQL server's mail functionality. But unfortunately I'm currently running SQL Server 2008 Express edition and it hasn't mail facilities. Please anyone help me to send e-mail using g-mail.

1
  • Its ASP. You are correct Cuong Le Commented Oct 3, 2012 at 6:59

4 Answers 4

2

This might help you start:

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); 
Sign up to request clarification or add additional context in comments.

2 Comments

As your tags say ASP.NET and C#, this is for ASP.NET and C#
It gives error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. pw2sm574022pbb.59"
1

Code for e-mail sending :--

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); 

i think this will help you

Comments

1

You can install an SMTP server and run this

[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 %> 

The above is for ASP *You said ASP. If you are using asp.net use Rajpurohit's sample code, but you need to install smtp server, or have access to a server that allows remote connection (either through relay or name/password authentication)

Comments

0

try this out

 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); } 

1 Comment

it gives me an error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.