首页 > 编程 > .NET > 正文

.net beta2 操作email的例子(转)

2024-07-10 13:04:26
字体:
来源:转载
供稿:网友
<%@ page language="vb" clienttarget="downlevel" %>
<%@ import namespace="system.web.mail" %>

<script language="vb" runat="server">
    sub btnsendmail_onclick(source as object, e as eventargs)
        dim mymessage as new mailmessage
        dim mymail    as new smtpmail
        dim stremail  as string

        if page.isvalid() then
            stremail = txtemail.text

            mymessage.from = "[email protected]" & request.servervariables("server_name")
            mymessage.to = stremail
            mymessage.subject = "e-mail sample from asp 101!"
            mymessage.body = "this message was sent from sample code by " & _
                "http://www.asp101.com.  it is used to show people how " & _
                "to send e-mail from an asp+ page.  this mail was sent " & _
                "from " & request.servervariables("server_name") & ".  " & _
                vbcrlf & vbcrlf & _
                "this email was sent to " & stremail & "."

            mymail.send(mymessage)

            frmemail.visible = false
            lblusermessage.text = "your message has been sent to " & stremail & "."
        end if
    end sub
</script>

<html>
<head>
<title>asp+ email sample</title>
</head>
<body>

<asp:label id="lblusermessage" text="enter your e-mail address:" runat="server" />
<form method="post" id="frmemail" runat="server">
    <asp:textbox id="txtemail" size="30" runat="server" />
    <asp:requiredfieldvalidator runat="server"
        id="validemailrequired" controltovalidate="txtemail"
        errormessage="please enter an email address."
        display="dynamic" />
    <asp:regularexpressionvalidator runat="server"
        id="validemailregexp" controltovalidate="txtemail"
        validationexpression="^[/w-][email protected][/w-]+/.(com|net|org|edu|mil)$"
        errormessage="please enter a valid email address."
        display="dynamic" />

    <asp:button id="btnsendmail" text="send mail!" onclick="btnsendmail_onclick" runat="server" />
</form>

</body>
</html>
-------------------------------------------
come from asp101.com

收集最实用的网页特效代码!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表