Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Question about how to send mail using Asp.net

  Asked By: Hayrah    Date: Jul 15    Category: Asp.net    Views: 14866
  

I have just read SAMs book on ASP.NET and am trying to apply it, but
it doesnt seem to have anything on sending mail. I had someone write
a routing for me last year in ASP (below) but I am not sure how to
convert it into ASP.net and particularly what objects to declare.
Here is how far I have got so far, maybe someone could give me some
more of the code!


sub send()
dim Mailer as ? = Server.CreateObject ("SMTPsvg.Mailer")
Mailer.FromName = "Dougie Shaw"
Mailer.FromAddress = "info@..."
Mailer.RemoteHost = "mail.dougieshaw.com"
Mailer.AddBcc = "dougieshaw@..."
Mailer.Subject = "Reminder" ' I need to vary this.
Mailer.BodyText = messagebody
Mailer.ContentType = "text/html"
if Mailer.SendMail then
response.write ("Mail Was Sent")
else
response.write ("Sendmail failed."& Mailer.response)
end if
end sub

Share: 

 

10 Answers Found

 
Answer #1    Answered By: Hamdan Younis     Answered On: Jul 15

it's very easy send  an email with asp.net... if you search on google for "send email asp.net" you'll get tons of resutls. Here you have one,
http://www.aspfree.com/aspnet/email.aspx

if you need something more advanced you can get AspNetEmail. You can find this amazing component @ www.aspnetemail.com

Also, you can get help on ASP.Net & Email issues @
http://groups.yahoo.com/group/AspNetEmail

 
Answer #2    Answered By: Laaibah Malik     Answered On: Jul 15

Ive checked out some of the links and am getting some useful
results. I know now to add the system.web.mail at the top and how to
dim the object But I still have a few questions.

1. Do you need to download these things. Won't my server have an
object that can alread do it.
2. THe main problem is now I have the code below, the compiler says
BC30188: Declaration expected at the Mailfrom= "Dougie Shaw" line
when I have already declared Mailer in the previous line. WHy is
that?


<%@ Page language="VB" AutoEventWireup="false" aspcompat=true%>
<%@ import namespace='system.data.oledb' %>
<%@ import namespace='system.data' %>
<%@ import namespace='System.Web.Mail' %>
<script language="VB" runat="server">

dim Mailer as new MailMessage
Mailer.From = "Dougie Shaw"
Mailer.To="dougieshaw@..."
mailer.BodyFormat = MailFormat.Html
Mailer.FromAddress = "info@..."
Mailer.RemoteHost = "mail.dougieshaw.com"
Mailer.AddBcc = "dougieshaw@..."
Mailer.Subject = "Reminder"
Mailer.Body = messagebody
Mailer.ContentType = "text/html"
SmtpMail.Send(mail)
if Mailer.SendMail then
response.write ("Mail Was Sent")
else
response.write ("Sendmail failed."& Mailer.response)
end if

response.write("<br><br><font size=3 color=red>sent to
day</font><br>")
response.write("<br>"& name)
response.write("<br>")
response.write(""& messagebody)
</script>

 
Answer #3    Answered By: Daw Boonliang     Answered On: Jul 15

You have to put that code inside an event handler like Page_Load, or a
button click, in this way:


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

If request.form("EmailAddress") <> ""
Dim mail  As New MailMessage
mail.From = "youraddress@..."
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<br><a href='http://aspfree.com/aspnet/email.aspx'>Wonder how
this is done?</a><br><br><a
href='http://aspfree.com/aspnet/setupcdonts.aspx'>Wonder How to setup
CDONTS?</a>"
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "LocalServerName"
SmtpMail.Send(mail)
End If
End Sub

Then when you define the button (<input>) you should use
OnServerClick="btn_Click" or if you use a Button webcontrol
(<asp:Button>) define the OnClick event handler

 
Answer #4    Answered By: Christie Bradley     Answered On: Jul 15

Definitely making progress here!

Its in the event handler, I have text boxes to submit to it, all the Mail. Tags work now.

The error I get now is BC30188: Declaration expected

At the line that says SmtpMail.SmtpServer = "LocalServerName"

I havent get downloaded the aspfree component for the simple reason that I am not at the server, its in the office and its 9pm so the guy to do it wont be in till the morning. Will it work without this?

 
Answer #5    Answered By: Wendy Harrison     Answered On: Jul 15

aspfree doesn't have any component... I was just refering to one of his tutorials to send  mail...
The smtp server property is the name or the ip of the smtp server (self-descriptive property I think ;). Just don't set that property and the local IIS smtp server would be used. If you want to use another smtp set that property (for instance mail.myisp.com)

 
Answer #6    Answered By: Noah Evans     Answered On: Jul 15

I just changes this property
Mailer.To="francisxavaz@..."
Mailer.From="sakthivel.atwpdc.com"
It isnt working!!!What else do I need to do in the
Code
to send  a mail.

 
Answer #7    Answered By: Candace Foster     Answered On: Jul 15

Can you show us all the code and errors. Have you specified a SMTPSERVER property value (either Netbios or DNS name)?

 
Answer #8    Answered By: Jo Fowler     Answered On: Jul 15


<%@ Page language="VB" AutoEventWireup="false"
aspcompat=true%>
<%@ import namespace='system.data.oledb' %>
<%@ import namespace='system.data' %>
<%@ import namespace='System.Web.Mail' %>
<script language="VB" runat="server">

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

dim Mailer as new MailMessage

If request.form("EmailAddress") <>""""

Mailer.To="francisxavaz@..."

mailer.BodyFormat = MailFormat.Html

Mailer.Bcc = "francisxvaz@..."

Mailer.Subject = "Testing!!!!!!!!"

Mailer.From="sakthivel.atwpdc.com"

Mailer.Body = "hi"

Smtpmail.SmtpServer = "80.0.0.54"

Smtpmail.Send(mailer)

End If

End Sub


SmtpMail.Send(Mailer)

if Mailer.SendMail then

response.write ("Mail Was Sent")

else

response.write ("Sendmail failed."&
Mailer.response)

end if



response.write("<br><br><font size=3
color=red>sent to day</font><br>")

response.write("<br>"& name)

response.write("<br>")

response.write(""& messagebody)

</script>
<html>
<body>
<form runat='server' ID="Form1">
<b>Enter Name
<br>
<asp:textbox id='name' runat='server' /><br>
Enter Email</b>
<br>
<asp:textbox id='email' runat='server' /><br>
Enter Message<b><br>
<asp:textbox id='message' runat='server' /><br>
How long till first send?</b>
<br>
<asp:textbox id='firstsend' runat='server' /><br>
Then how often?</b>
<br>
<asp:textbox id='frequency' runat='server' />
<asp:linkbutton id='button1' runat='server'
Text='Add' onfiltered='Add' />
</form>
</body>
</hmtl>

 
Answer #9    Answered By: Blaze Fischer     Answered On: Jul 15

and the err Comes BC30188: Declaration expected.

Line 41: SmtpMail.Send(Mailer)

 
Answer #10    Answered By: Pam Harrison     Answered On: Jul 15

Your smtp server should not be a share name but rather either a NETBIOS or DNS name i.e. NETBIOS :MYSMTPSERVER ß-> DNS: Mailserver.MYdomain.Com

 
Didn't find what you were looking for? Find more on Question about how to send mail using Asp.net Or get search suggestion and latest updates.




Tagged: