Sending Mail

  • Thread starter Joe via DotNetMonster.com
  • Start date
J

Joe via DotNetMonster.com

Hi,

I'm trying out a test mail script but it doesn't seem to work. The error I
get is that mail is not declared on the mail.To line.

Also, do I need to specify the SMTP Server? I have it commented out:

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Mail" %>

<script runat="server">

Dim mail As New MailMessage()
mail.To = "(e-mail address removed)"
mail.From = "(e-mail address removed)"
mail.Subject = "this is a test email."

mail.BodyFormat = MailFormat.Html
mail.Body = "this is my test email body.<br><b>this part is in bold</b>"
'SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)
</script>
<html>
<head>
</head>
<body>
<form runat="server">
</form>
</body>
</html>


Thanks
 
T

Teemu Keiski

Hi,

try wiring the code into an event handler in the <script> element

Private Sub Page_Load(sender As Object,e As EventArgs) Handles MyBase.Load
'Code goes here
End Sub

And, yes it is recommended to specify the SMTP Server. It should use the
default local mail system (in IIS, placing eml files into directories) if
server isn't given, but it has had certain problems (though you'd face error
messages at that point). Just give it "localhost" or "127.0.0.1" and then
you might need to enable mail relaying in IIS SMTP Service (if you use it).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top