473,795 Members | 2,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending an email in asp.net2.0 using C#

3 New Member
HI to all,
Here I am working on asp.net2.0 and C# can u pls help me for Sending an email in asp.net2.0 using C#,

thanks in Advance ...
Aug 13 '07 #1
2 2258
thaiwhere
3 New Member
HI to all,
Here I am working on asp.net2.0 and C# can u pls help me for Sending an email in asp.net2.0 using C#,

thanks in Advance ...
Hi !
You can using this code below :
//*************** *************** ************
public void Send(string from, string to, string cc, string subject, string data, string xslFormatFilePa th)
{
try
{
try
{
string body = TransformXml(da ta, xslFormatFilePa th);

MailMessage message = new MailMessage();
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.From = from;
message.To = to;
message.Cc = cc;
message.Subject = subject;
message.Body = body;
message.BodyFor mat = MailFormat.Html ;

try
{
SmtpMail.SmtpSe rver = LMSContext.Mail Server;
//SmtpMail.SmtpSe rver.Insert(0, LMSContext.Mail Server);
SmtpMail.Send(m essage);
}
catch(System.We b.HttpException ex)
{
Log.Logger.LogE rror("Send mail error",ex);
return;
}
}
catch(IndexOutO fRangeException ex)
{
Log.Logger.LogE rror("Send mail error",ex);
return; }
}
catch(System.Ex ception ex)
{
Log.Logger.LogE rror("Send mail error",ex);
return; }
}

//*************** *************** ************
private string TransformXml(st ring data, string xslPath)
{
System.Text.Str ingBuilder strBuilder = new System.Text.Str ingBuilder();
System.IO.Strin gWriter sw = new System.IO.Strin gWriter(strBuil der);

XmlDocument objXmlDoc = new XmlDocument();


objXmlDoc.LoadX ml(data);
//We create StringWriter object for output.
XslTransform objTransform = new XslTransform();
XmlUrlResolver resolver = new XmlUrlResolver( );
resolver.Creden tials = System.Net.Cred entialCache.Def aultCredentials ;

// Set credentials for loading the stylesheet
// trans.Load(Serv er.MapPath("MyS tyle.xsl"), XsltSettings.De fault, resolver);

objTransform.Lo ad(xslPath, resolver);
objTransform.Tr ansform(objXmlD oc, null, sw, null);
sw.Close();
return sw.ToString();
}
//*************** *************** ************

Regards,
Thai
Aug 13 '07 #2
CBasha
3 New Member
Hi !
You can using this code below :
//*************** *************** ************
public void Send(string from, string to, string cc, string subject, string data, string xslFormatFilePa th)
{
try
{
try
{
string body = TransformXml(da ta, xslFormatFilePa th);

MailMessage message = new MailMessage();
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.From = from;
message.To = to;
message.Cc = cc;
message.Subject = subject;
message.Body = body;
message.BodyFor mat = MailFormat.Html ;

try
{
SmtpMail.SmtpSe rver = LMSContext.Mail Server;
//SmtpMail.SmtpSe rver.Insert(0, LMSContext.Mail Server);
SmtpMail.Send(m essage);
}
catch(System.We b.HttpException ex)
{
Log.Logger.LogE rror("Send mail error",ex);
return;
}
}
catch(IndexOutO fRangeException ex)
{
Log.Logger.LogE rror("Send mail error",ex);
return; }
}
catch(System.Ex ception ex)
{
Log.Logger.LogE rror("Send mail error",ex);
return; }
}

//*************** *************** ************
private string TransformXml(st ring data, string xslPath)
{
System.Text.Str ingBuilder strBuilder = new System.Text.Str ingBuilder();
System.IO.Strin gWriter sw = new System.IO.Strin gWriter(strBuil der);

XmlDocument objXmlDoc = new XmlDocument();


objXmlDoc.LoadX ml(data);
//We create StringWriter object for output.
XslTransform objTransform = new XslTransform();
XmlUrlResolver resolver = new XmlUrlResolver( );
resolver.Creden tials = System.Net.Cred entialCache.Def aultCredentials ;

// Set credentials for loading the stylesheet
// trans.Load(Serv er.MapPath("MyS tyle.xsl"), XsltSettings.De fault, resolver);

objTransform.Lo ad(xslPath, resolver);
objTransform.Tr ansform(objXmlD oc, null, sw, null);
sw.Close();
return sw.ToString();
}
//*************** *************** ************

Regards,
Thai
Hi thaiwhere,
Thanks for ur helping, I wil try as u said;
thanks once again....
Basha...
Aug 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3622
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is smtpMail.Send("from@here.com", to@there.com, "Message subject", "Message Body") I'm sending it to my own email address on a different server using a dummy
1
8186
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
1
1695
by: Winista | last post by:
I have a library that reads PDF file and manipilates its content. And I use SharpZip library to decompress the streams included in PDF file. All well and good. I have 3 lines of my test code that takes a PDF file and spits out the required content from the file. It all works fine in .Net.1. environment. Now I wrote the same 3 lines of code in .Net2.0 console test application and use the assemblies for PDF library and SharpZip compiled...
4
2519
by: hvj | last post by:
I need to run a .NET1.1 program in a .NET2.0 CLR. The .NET1.1 exe starts correctly in .NET2.0. Now I want to debug in Visual Studio 2005. But when I try to open the .NET1.1 project, Visual Studio wants to convert it to .NET2.0 what I don't want. How can I make Visual Studio open a .NET1.1 project for me in order to attach to a .NET2.0 process in which it runs to debug it? Or is there a better way to reach my goal: debugging a .NET1.1...
4
1869
by: InnoCreate | last post by:
Hi everyone, I've developed a couple of asp.net1.1 websites and these are viewable using my mobile phone. I've now moved over to asp.net2 and i'm unable to view asp.net2 websites on my phone. I've stripped a page down to only output HTML4.01 and a single line of text with no formatting and it's still not viewable. Can anyone help me - i don't want to develop a asp.net2 mobile website - i want to develop a standard asp.net2 website that...
0
1175
by: Frank Carius [MVP] | last post by:
I'm using .NET2.0 Framework and send a message using the SMTPClient from System.Net.Mail to send a message directly (without using Pickup) Everything works fine but i have not found a way to terminate the connection "gracefully" Sending a mail using SMTPClient results in >HELO myhostname <250 ok >MAIL FROM: sender mail address
1
1347
by: =?Utf-8?B?SWJyYWhpbQ==?= | last post by:
I have probelm to deploy ASP.net2 Application implement in this Application the Virtual path provider techinque what I have done : 1- built the web Application with Asp.net2 as File system Application 2- Implement the Virtual path provider (Virtual path , virtual Directory , Virtual File) in this Application to call Virtual file or virtual directory
1
1502
by: KUTTAN | last post by:
I am trying to send emailes ,but it leades to exeption the exeption message is "Failure sending mail." Try Dim message As New MailMessage()
1
1092
smahdis
by: smahdis | last post by:
Hello Friends, I am new to this Forum. Let me ask my question straightly I faced a problem in vb 2005 and that is: I want to send Email using System.net.mail but I couldn't find anything about Authentication there. Can you please give me a simple code for sending an email using SMTP and Authentication in VB 2005 (.net2)?!
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.