473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Sending Mails through ASP.Net

Hi!!
I'm trying to send mail thro' asp.net using SMTP........
but it doesn't work...
I'm using following code:
MailMessage msg=new MailMessage();
StringWriter strwr=new StringWriter();
HtmlTextWriter htmlwr=new HtmlTextWriter(strwr);
htmlwr.RenderBeginTag("html");
htmlwr.RenderBeginTag("head");
htmlwr.Write("Welcome");
htmlwr.RenderEndTag();
htmlwr.RenderBeginTag("body");
htmlwr.Write("Hello frnd....welcome to our website");
htmlwr.Write("Thanks for registration");
htmlwr.RenderEndTag();
htmlwr.RenderEndTag();
msg.From="abcdefg@yahoo.com";
msg.To=txtemail.Text;
msg.Subject="Welcome to StateMgmt";
msg.Body=strwr.ToString();
msg.BodyFormat=MailFormat.Html;
SmtpMail.Send(msg);


Can anyone help me out.....I don't know my concept is correct or not.....i'm a beginner rite now....
Any response will be appreciated..
Jan 20 '07 #1
4 1435
kenobewan
4,871 Expert 4TB
I can't see your smtpserver declared, declare this and post the result. Also make sure that you use system.web.mail.

Hope that this helps.
Jan 20 '07 #2
Hello!
Thro' the above code i have a mail saved in my inetpub\mailroot\queue folder as an internet mail message......
As u said when i declare the smtpserver as follows after mailmsg.bodyformat:

SmtpMail.SmtpServer="localhost";
try
{
SmtpMail.Send(msg);
Response.Redirect("welcome.aspx");

}
catch(Exception exc)
{
Response.Write("Sorry ur mail could not be sent:"+exc.ToString());
}

Now it gives me following error:
"Sorry ur mail could not be sent:System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x8004020F): The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for rhyme2ri2@gmail.com --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(T ype type, Object obj, String methodName, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) --- End of inner exception stack trace --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at StateManagement.WebForm1.cmdregister_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\statemanagement\login.aspx.cs:l ine 81 "

Sorry i know it's quite long but i don't get anything from that.....
I wud also like to know if i'll be able to send mails from localhost??
Jan 22 '07 #3
kenobewan
4,871 Expert 4TB
Here are some suggestions as to what may be going wrong:
System.Web.Mail FAQ
Jan 23 '07 #4
Is your machine in an network, or standalone?
If ur machine is in network. then For STMPSever directly specify ur SMTP Mail Server.

Also see if u r using Anti Virus. If yes then see whether it is blocking port 25 or not in Port blocking area. If it is blocking it then unblock it.
Jan 29 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Stuart Mueller | last post by:
I have an exchange server, that I sometimes use to perform mail shots to clients on our database, these can be upwards of 1000 at a time. As we don't want different clients to see who we are...
3
by: martin smith | last post by:
Here's the scenario. I'm currently using cdosys/asp to send mail to our SMTP server. We use a product called MailFilter to check for SPAM. It doesn't work very well. If MailFilter isn't working...
1
by: Jayakumar | last post by:
HI, I am using System.web.mail class in my application to send mails. I am using SMTP server for the same. I can send mail to the intranet addresses, But when i send mails to Hotmail or other...
7
by: Lau | last post by:
I need to send 1000 emails from an asp.net website. Normally I would use System.Web.Mail.MailMessage() to send thru an SMTP server. But the large amount of emails results in a timeout. My server...
5
by: cashdeskmac | last post by:
I am writing a web application will will be hosted on a few peoples laptops as a local application. It will send e-mails once the user connects to the internet. How can I set up the "Mail.From"...
1
by: Dirk Goossens | last post by:
Hello! I'm sending E-mails to mailadresses in a table, using the code below. How can I send more than one attachment? Access can find the file to be send in this field: MY_EMAILATTACHMENT_FIELD...
8
by: Michel Posseth [MCP] | last post by:
Hi does someone has experience with this ?? i have made a lot of apps in the past that were capable of sending e-mails the server i then talked to was a Linux SMTP server and it worked great ...
1
by: gemma.gill | last post by:
Hi There, I have a button on a form within access that sends a verification e- mail. My problem is that these e-mails are sending from individual user accounts rather than a genieric mailbox. ...
3
by: dskinibbyb | last post by:
Hi Everybody, I am sending mail using the new class in .Net 2.0. Here while sending internal mails it is giving me problem. Carriage return, Line feed and Spaces are lost while sending mails....
2
by: srinivaspnv21 | last post by:
hi every one, plz help me out, i have to send mails from my asp.net page.... I have tried a code where mails are going only to gmail users the code is ... namespace: using System.Web.Mail;...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.