Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : .NET : ASP.NET : Same functionality in VB.NET Signup · Login
Author Thread
Same functionality in VB.NET
Posted in tutorial: Sending e-mail with attachments from an ASP.NET page
·  stoneypointe
User
Joined: 30 May 2003
Total Posts: 1
Same functionality in VB.NET
Posted: 30 May 2003
Hi there
Great article.
Are you aware if I can get this code anywhere in VB.Net?

Regards


Marcelo

ASP.Net Rules!!!!
·  RVen
User
Joined: 11 Jul 2003
Total Posts: 1
vb
Posted: 11 Jul 2003
<%@ Page Language="VB" EnableSessionState="False" EnableViewState="True" Trace="True" Debug="True" Strict="True" %>
<%@ Import Namespace="System.Web.Mail" %>
<script language="VB" runat=server>
Sub Page_load(Sender as Object, E as EventArgs)


If request.form("EmailAddress") = "" Then
dim strResponse as string = "<h2>Send Email using ASP.NET formatted in HTML</h2>"
lblMessage.Text = strResponse
Else
dim strResponse as string = "You just sent an email message formatted in HTML to:<br><h2>" & request("EmailAddress") & "</h2>"
lblMessage.Text = strResponse
End If

End Sub

Sub btn_Click(sender as Object, e as System.EventArgs)

If request.form("EmailAddress") <> ""
Dim mail As New MailMessage
mail.From = "you@domain.com"
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from ASPFree.com using ASP.NET and Cdonts"
mail.BodyFormat = MailFormat.Html
Dim MyAttach As New MailAttachment("C:\MyTable.xml")
mail.Attachments.Add(MyAttach)
smtpMail.SmtpServer = "yourmailserverip"
SmtpMail.Send(mail)
End If
End Sub

</script>
<html>
<head>
</head>
<body>
<asp:Label id="lblMessage" Font-Name="Verdana" Width="400px" BorderStyle="solid" BorderColor="#cccccc" runat="server"/>

<form method="post" name="form1" runat="server" runat="server">
Email Address:<input type="text" name="EmailAddress" size="30" value=""><br><br>
<input type="Submit" id="btnSubmit" OnServerClick="btn_Click" value="Sending Email with ASP.NET" name="b1" runat="server" />
</form>
</body>
</html>
·  kiran
User
Joined: 17 Dec 2003
Total Posts: 1
Here is another solution - just some slight changes to C# code
Posted: 17 Dec 2003
SM.aspx

<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System.web.Mail" %>
<%@ import Namespace="system.io" %>

<script runat="server">

Sub sendMessage_Click(sender As Object, e As EventArgs)
Dim mailmsg as new MailMessage
Dim mailattach as mailattachment
Dim attachname as String

mailmsg.From = from.text
mailmsg.To = tomail.text
mailmsg.subject = subject.text

If mformat.selecteditem.text = "Text" then
mailmsg.bodyformat = mailformat.Text
Else
mailmsg.bodyformat = mailformat.Html
End If

mailmsg.body = body.text

attachname = MyFile.PostedFile.FileName

If (attachname <> "") then
attachname = attachname.substring(attachname.lastindexof("\")+1)
MyFile.PostedFile.saveAs(Server.MapPath(attachname))
mailattach = new mailattachment(Server.MapPath(attachname))
mailmsg.attachments.add(mailattach)
End if
smtpmail.send(mailmsg)
If (attachname <> "") then
File.Delete(Server.MapPath(attachname))
Response.Write("Mail sucessfully sent to " + tomail.Text)
Response.Write("<a href='SM.aspx'>click here to send more mails.")
End If
End Sub
</script>

Where:
MyFile is the File control. <input type=file...>

and form tag should be as follows
<form action="SM.aspx" method="post" enctype="multipart/form-data" runat="server">

with a submit button
<input type="submit" value="Send Message!" runat="server" onserverclick="sendMessage_Click" />

Kiran...........

Users Who Have Visited This Thread In Last 24 Hours
4 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.