dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPhagu Mahato
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » ASP.NET »

How to send an email using bo,bal and dal


Posted Date: 07 Aug 2012      Posted By:: anand babu     Member Level: Silver    Member Rank: 2051     Points: 2   Responses: 3



send an email using 4-tier architecture.
3 fields i.e, name ,email,description and submit button
store this data in database and what ever data we enter in description should send to an particular email.
please send me the complete code its urgent.




Responses

#683518    Author: Paritosh Mohapatra      Member Level: Diamond      Member Rank: 6     Date: 07/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

You can use the mail server of existing mail providers like yahoo or google.

To send mail from the existing mail providers you need 4 things:

1) Sender EMail ID.
2) Sender Password.
3) Sender SMTP service provider. Example: gmail uses smtp.gmail.com.
3) SMTP Port. By default port 25 is used. Different Mail Server uses different port numbers for sending mail using and without using SSL. If you are using Gmail without SSL, then set the Port Number to 25 and client.EnableSsl to false. If you want send mail with SSL enabled, you can use Port Number 587 and set client.EnableSsl to true.


Please check the following code:


using System.Net.Mail;

protected void Button1_Click(object sender, EventArgs e)
{
string DisplayName = "Your Name";
string Subject = "Your Subjecj goes here...";
string Body = "Create the body of the E-Mail here...";
string To = "receiver@domain.com";
SendMail(DisplayName, Subject, Body, To);
}

public string SendMail(string DisplayName, string Subject, string Body, string To)
{
int ClientPort;
string SenderEmailId, SenderPassword, SenderSmtpAddress;
try
{
ClientPort = 25;
SenderSmtpAddress = "smtp.domain.com";
SenderEmailId = "sender@domain.com";
SenderPassword = "senderpassword";

// Building the Message
MailMessage msg = new MailMessage();
msg.To.Add(To);
msg.From = new MailAddress(SenderEmailId, DisplayName, System.Text.Encoding.UTF8);
msg.Subject = Subject;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = Body;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;

// Adding the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(SenderEmailId, SenderPassword);
client.Port = ClientPort;
client.Host = SenderSmtpAddress;
client.EnableSsl = true;
client.Send(msg);
}
catch (SmtpException ex)
{
return ("Due To " + ex.Message);
}
return "Mail Sent Successfully";
}



Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM



 
#683523    Author: Pawan Awasthi      Member Level: Diamond      Member Rank: 4     Date: 07/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

Hai Anand,
If you want to implement your requirements in 4-tier architecture using UI, BO, BL and DL then the first thing is that you need to create the Business Object class which will contain all your properties like below:

Class EmployeeBO
{
public string Name{get;set;}
public string Email{get;set;}
public string Description{get;set;}
}

Now your one class is completed. You can have this in a separate class library project and build it.
The next thing is that you need to crete the dataAccess layer with the method to insert the records.
Create a Class Library Projec with the Class as:

using BusinessObjectProject;//reference must be added to include the class of Business object project
Class EmployeeDL
{
public void SaveDetails(EmployeeBO objEmployeeBO)
{
string name = objEmployeeBO.Name;
string email = objEmployeeBO.Email;
string description = objEmployeeBO.Description;
// write the method to send the mail with the above details(can be used the above post method)
}
}

Build the class library project.
Now you can create your business layer as:
Create a Class Library project and add a class:

using BusinessObjectProject;//reference must be added to include the class of Business object project
using DataAccessLayerProject;//;//reference must be added to include the class of data access project

Class EmployeeBL
{
public void SaveDetails(EmployeeBO objEmployeeBO)
{
EmployeeDL objEmployeeDL = new EmployeeDL();
objEmployeeDL.SaveDetails(objEmployeeBO);
}

Build the Project.
Now you can have the UI layer where you will have the button click event through which the actual data will be passed on to other layers as:

using BusinessObjectProject;//reference must be added to include the class of Business object project
using BusinessLayerProject;//;//reference must be added to include the class of business layer project


Class Employee
{
protected void btnSave_Click(Object sender, EventArgs e)
{
EmployeeBO objEmployeeBO = new EmployeeBO();
objEmployeeBO.Name = txtName.Text;
objEmployeeBO.Email = txtEmail.Text;
objEmployeeBO.Description = txtDescription.Text;

EmployeeBL objEmployeeBL = new EmployeeBL();
objEmployeeBL.SaveDetails(objEmployeeBO);
}

Hope it will be helpful to you.

Regards,
Pawan Awasthi(DNS MVM)
+91 8143683708 (pawansoftit@gmail.com)
Outstanding Contribution Award..NTT Data Inc



 
#683545    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 08/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

You can send the mail from the Data access layer, but from BO layer you need to pass the details capture from UI
here is a sample code to send the mail


protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailAddress SendFrom = new MailAddress(txtFrom.Text);
MailAddress SendTo = new MailAddress(txtTo.Text);

MailMessage MyMessage = new MailMessage(SendFrom, SendTo);

MyMessage.Subject = txtSubject.Text;
MyMessage.Body = txtBody.Text;

Attachment attachFile = new Attachment(txtAttachmentPath.Text);
MyMessage.Attachments.Add(attachFile);

SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
emailClient.Send(MyMessage);

litStatus.Text = "Message Sent";
}
catch (Exception ex)
{
litStatus.Text=ex.ToString();
}
}


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM






 
Post Reply
You must Sign In to post a response.

Next : Listview Example Total Controls
Previous : GMail Mails To Retrieve
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.