C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Sending EmailsFrom ASP.NET Web Page


Posted Date: 20 Mar 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms

Posted By: sharad       Member Level: Bronze
Rating:     Points: 7



The code sample is a simple method for sending Email from a ASP.NET web page. It uses a MailMessage object to send the mail message.

The code is written in VB.

				
<HTML>
<HEAD>
<title>WebForm1</title>
<script language="vbscript" runat="server">
SUB MYMAIL(A AS OBJECT,E AS EVENTARGS)
DIM MAILOBJ AS NEW MAILMESSAGE
MAILOBJ.FROM=FROMADDRESS.text
MAILOBJ.TO=TOADDRESS.text
MAILOBJ.CC=CCADDRESS.text
MAILOBJ.BCC=BCCADDRESS.text
MAILOBJ.SUBJECT=SUBJECT.text
mailobj.body=message.text

'IF LEN(ATTACHMENTS.text)>0) THEN
' MAILOBJ.ATTACHMENTS.ADD(NEW MAILATTACHMENT(ATTACHMENTS.text))
' else
'response.write("No attchments found")
'end if

try
SMTPmail.send(mailobj)
status.text="message sent successfully"
catch ex as exception
status.text="message not sent"
'response.write(ex.message)
end try
END SUB

sub clearBOX(sender as object,e as eventargs)
FROMADDRESS.TEXT=""
TOADDRESS.TEXT=""
CCADDRESS.TEXT=""
BCCADDRESS.TEXT=""
SUBJECT.TEXT=""
MESSAGE.TEXT=""
status.text=""

end sub

</script>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body bgColor="gainsboro">
<form id="Form1" method="post" runat="server">
<table>
<TBODY>
<tr>
<th>
MESSAGE FULL EX</th></tr>
<tr>
<td>FROM</td>
<TD width="400"><asp:textbox id="FROMADDRESS" Width="296px" Runat="server"></asp:textbox></TD>
</tr>
<tr>
<td>TO
</td>
<TD><asp:textbox id="TOADDRESS" Width="296px" Runat="server"></asp:textbox></TD>
</tr>
<tr>
<td>CC
</td>
<td><asp:textbox id="CCADDRESS" Width="296px" Runat="server"></asp:textbox></td>
</tr>
<tr>
<td>BCC
</td>
<TD><asp:textbox id="BCCADDRESS" Width="296px" RUNAT="server"></asp:textbox></TD>
</tr>
<tr>
<td>SUBJECT</td>
<td><asp:textbox id="SUBJECT" Width="296px" Runat="server"></asp:textbox></td>
</tr>
<tr>
<TD>ATTACHMENTS</TD>
<TD><asp:textbox id="ATTACHMENTS" Width="296px" Runat="server" Height="24px"></asp:textbox></TD>
</tr>
<tr>
<td style="HEIGHT: 127px">MESSAGE</td>
<td style="HEIGHT: 127px"><asp:textbox id="message" Width="296px" Runat="server" Height="146px"></asp:textbox></td>
</tr>
<tr>
<td>SEND</td>
<td><asp:button id="B1" onclick="MYMAIL" Width="104px" Runat="server" Height="22px" Text="SEND"></asp:button><asp:button id="b2" onclick="clearbox" runat="server" Width="112px" Height="22px" Text="Newmail"></asp:button></td>
<td></td>
</tr>
<tr>
<td><asp:label id="status" Runat="server"></asp:label></td>
</tr>
</TBODY>
</table>
</form>
</body>
</HTML>




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Use ASP.NET to send E-Mails  .  Send E-Mails using ASP.NET  .  Send E-Mails in VB.NET  .  Send E-Mails from Web Page using ASP.NET  .  Send E-Mails from Web Page  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Reading a Web Page with HttpRequest in C#
Previous Resource: How to access master page controls & writing button click event
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use