473,513 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send email form C#

Hello All,

I wrote the follownig program

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Web.Mail;
  3. public class MailHelper
  4. {
  5. public static void SendMail(string mailId, string author, string email,
  6. string title, string msgDate, string comment)
  7. {
  8. String msg = String.Format("{0} (email: {1}) has just posted a comment
  9. on the message \"{2}\" of your BLOG that you posted at {3}. Here's the
  10. comment: {4}{4}{5}",
  11. author,
  12. email,
  13. title,
  14. msgDate,
  15. Environment.NewLine,
  16. comment
  17. );
  18. try
  19. {
  20. //SmtpMail.SmtpServer = "localhost";
  21. MailMessage mail = new MailMessage();
  22. mail.To = mailId;
  23. mail.From = "ab******@hotmail.com";
  24. mail.Subject = "New BLOG comment notification";
  25. mail.Body = msg;
  26. SmtpMail.Send(mail);
  27. }
  28. catch(Exception ex)
  29. {
  30. Console.WriteLine(ex);
  31. Console.WriteLine("*****************");
  32. Console.WriteLine(ex.InnerException.Message);
  33. Console.WriteLine("*****************");
  34. Console.WriteLine(ex.InnerException.InnerException.Message);
  35. throw ex;
  36. }
  37. }
  38. }
  39.  
The code doesn't throw any exception ... but it doesn't send the mail as
well.

I have configured the SMTP service on my local machine itself. I have
also gone into SMTP server properties and into the "Access->Relay"
option and added my machine IP (127.0.0.1 and my ip address) into the
list of "only the list below" option.

Please do help me... why am I not able to send the email?

regards,
Abhishek.

Nov 15 '05 #1
5 3895
Abhishek Srivastava wrote:
[cut]

Please do help me... why am I not able to send the email?

regards,
Abhishek.


Hi,
Try to uncomment
Expand|Select|Wrap|Line Numbers
  1. SmtpMail.SmtpServer = "localhost";
  2.  

Greets
Patrick
Nov 15 '05 #2
If I do that I get the exception

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 (0x80040213): The transport
failed to connect to the server.

--- 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 BLogComponents.MailHelper.SendMail(String mailId, String author,
String email, String title, String msgDate, String comment) in
c:\myapps\dotnet\blog\components\mailhelper.cs:lin e 25
*****************
Exception has been thrown by the target of an invocation.
*****************
The transport failed to connect to the server.
Patrick Schwegler wrote:
Abhishek Srivastava wrote:
[cut]

Please do help me... why am I not able to send the email?

regards,
Abhishek.


Hi,
Try to uncomment
Expand|Select|Wrap|Line Numbers
  1.      SmtpMail.SmtpServer = "localhost";
  2.  


Greets
Patrick


Nov 15 '05 #3
Abhishek Srivastava wrote:
If I do that I get the exception

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 (0x80040213): The transport
failed to connect to the server.

--- 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 BLogComponents.MailHelper.SendMail(String mailId, String author,
String email, String title, String msgDate, String comment) in
c:\myapps\dotnet\blog\components\mailhelper.cs:lin e 25
*****************
Exception has been thrown by the target of an invocation.
*****************
The transport failed to connect to the server.
Patrick Schwegler wrote:
Abhishek Srivastava wrote:
[cut]

Please do help me... why am I not able to send the email?

regards,
Abhishek.


Hi,
Try to uncomment
Expand|Select|Wrap|Line Numbers
  1.      SmtpMail.SmtpServer = "localhost";
  2.  


Greets
Patrick


It almost sounds like your SMTP service is either not running or not
accepting calls. Try going to Outlook Express and set the SMTP server to
be localhost and try sending an email. Also, check the BadMail Folder
under mailroot directory. You might get some insight.

--
Girish Bharadwaj

Nov 15 '05 #4
Is it the only to send an Email using CDO ?
In the past, CDO was meaning of having at least a ms-exchange client on
the pc (like outlook), and also a correct profile.

Is there another way to send an email more directly ? a SMTP Class ?

Regards,
Cybertof.
In article <OQ**************@TK2MSFTNGP12.phx.gbl>, ab******@nospam.net
says...
If I do that I get the exception

System.Web.HttpException: Could not access 'CDO.Message' object. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->

Nov 15 '05 #5
You will need outlook or outlook express to use the SMTPMail Class as it
utilizies the CDO object.

If you don't want to rely on CDO, you will need to write a class that can
connect to an SMTP server and execute the neccessary commands.
"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
Is it the only to send an Email using CDO ?
In the past, CDO was meaning of having at least a ms-exchange client on
the pc (like outlook), and also a correct profile.

Is there another way to send an email more directly ? a SMTP Class ?

Regards,
Cybertof.
In article <OQ**************@TK2MSFTNGP12.phx.gbl>, ab******@nospam.net
says...
If I do that I get the exception

System.Web.HttpException: Could not access 'CDO.Message' object. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2933
by: cooldv | last post by:
i have an *access database + ASP newsletter* that is working fine and it sends newsletter to ALL the email addresses in the DB. i want to send this newsletter to only a select group (like people with same name or same city etc). how do i do that? here is the code of newsletter. where should i make changes? Thanx in advance for ur help. ...
7
2535
by: Mario Leduc | last post by:
Hi, I have a page that sends user comments with CDONTS, works fine. Until I put a URL (http://192.168.0.1). If I use http://domain.com it works fine. Why with the numeric URL, CDONTS does not send the mail?? Thanks
1
1865
by: Kenshin | last post by:
Hey! I have another script where i pull all the information from the database and I want to send it to the person. What they do is they enter in their email, and if the email matches, than it will email them their login information. How do you grab the info and than use that info and put it into an email to send? Here is my code thus far...
1
4459
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the current window. I have a cgi script provided by my web host to send the contents of the form through email but they only show me how to use the cgi...
6
11163
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard...
1
2133
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
2
5622
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not support .asp,.aspx files, it supports PHP files, I'm searching in JavaScript ,but not found any matter, I'don't Know PHP.I'm having lot of...
2
2471
by: kennykenn | last post by:
Hi, Ive producd code to send an email after capturing info off a form,it works fine locally but when i put it live it doesnt work! the code is stopin at 'msg.send' any ideas, here the code! <%
5
2344
by: canajien | last post by:
I have a form that stores information in a table, but I also need it to send an email when a specific question, among the many, is answered with no the question is a simple drop box: <select name="safe_access"> <option value="0"></option> <option value="yes">Yes</option> <option value="no">No</option>
1
3592
by: Michael31277 | last post by:
I keep getting this error on my form code, but only when I keep the MailNewObj.Send in the code, so I know it is this... I get the 500 INTERNAL ERROR message.. I tried shutting off "friendly messages" in IE, but it still winds up with the same message... I am publishing to GoDaddy and the GoDaddy server is ASP/LINUX since I wanted a combination of...
0
7270
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7565
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7128
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.