[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Email and ASP.net

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
ndr-itsolutions
Asked:
ndr-itsolutions
1 Solution
 
esolveCommented:
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
 
Kamal KhaleefaInformation Security SpecialistCommented:
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
 
Monica PCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now