Solved

Email and ASP.net

Posted on 2013-01-20
3
397 Views
Last Modified: 2013-01-22
I am writing my first ASP.net web application with Web Developer Express 2010 and MS SQL 2008 Express. I have built a page in which a user can input details of software that is required to be deployed, I would like to create a button with the code behind it to send an email with the details of the task that has just been input, or at the least an email to state their is a task waiting.

How can I do this ?
0
Comment
Question by:ndr-itsolutions
3 Comments
 
LVL 6

Accepted Solution

by:
esolve earned 400 total points
ID: 38798314
This is probably the easiest:

using System.Net.Mail;

MailMessage message = new MailMessage();
            message.From = new MailAddress("sender@mydomain.com");

            message.To.Add(new MailAddress("recipient1@mydomain.com"));
            message.To.Add(new MailAddress("recipient2@mydomain.com"));
            message.To.Add(new MailAddress("recipient3@mydomain.com"));

            message.CC.Add(new MailAddress("carboncopy@mydomain.com"));
            message.Subject = "This is my subject";
            message.Body = "This is the content";
            //message.IsBodyHtml = true;

            SmtpClient client = new SmtpClient("smtp.mydomain.com");
            client.Send(message);

Depending on the host you might need authentication:

   SmtpClient smtp = new SmtpClient();
   smtp.Host = "smtp.gmail.com";
   smtp.Port = 587;
   smtp.EnableSsl = true;
   smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
   smtp.UseDefaultCredentials = false;
   smtp.Credentials = new System.Net.NetworkCredential(fromAddress.Address,fromPassword);


theres some more info here:

http://forums.asp.net/t/971802.aspx
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
http://support.microsoft.com/kb/310273
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 38799920
hi

  Dim message1 As New MailMessage("kns@kockw.com", TL_Email, "Temporary Gate Pass Request needs Approval", commen)
                    message1.IsBodyHtml = True

                    Dim emailClient As New SmtpClient("put your smtp")


'some time u need to provide some credintial like this
   '  Dim basicAuthenticationInfo As _
                    'New System.Net.NetworkCredential("your email", "your password")

                    '  emailClient.UseDefaultCredentials = False
                    '  emailClient.Credentials = basicAuthenticationInfo



 emailClient.Send(message1)
0
 
LVL 10

Expert Comment

by:Monica P
ID: 38799945
To send a Email..include needed namespace...

Imports System.Net.Mail

CAll the Below function name "sendemail" inside button click

Public Sub sendemail()
        Try

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            ' Dim attachment As System.Net.Mail.Attachment
            SmtpServer.Credentials = New  _
              Net.NetworkCredential("Username", "Password")
            SmtpServer.Port = 587
            SmtpServer.Host = "123.122.111.111"

            mail = New MailMessage()

            mail.From = New MailAddress("Reports@test.com")
            mail.CC.Add("dmc@test.com")
            mail.To.Add("abcr@tt.com")
            mail.Bcc.Add("akila@tt.com")

            mail.Subject = "Report of Stock"
            mail.Body ="Incllude body of email..by reading the value from DATABASE"
            SmtpServer.Send(mail)
        Catch ex As Exception
        End Try
    End Sub
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now