-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.

Community
  • 1
  • 1
MaDu_LK
  • 2,700
  • 5
  • 24
  • 39

4 Answers4

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);
McGarnagle
  • 96,448
  • 30
  • 213
  • 255
Sidharth Mudgal
  • 4,026
  • 16
  • 24
  • As your tags say ASP.NET and C#, this is for ASP.NET and C# – Sidharth Mudgal Oct 03 '12 at 04:33
  • 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" – MaDu_LK Oct 03 '12 at 07:51
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 = "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
%>

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)

albattran
  • 1,807
  • 1
  • 10
  • 14
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

Rajpurohit
  • 1,821
  • 2
  • 15
  • 19
0

try this out

            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);
            }
MaDu_LK
  • 2,700
  • 5
  • 24
  • 39
Dinithi
  • 667
  • 4
  • 21
  • 44
  • 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" – MaDu_LK Oct 03 '12 at 07:45