By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

i have a problem : with sending email

P: 10
(using System.Net.Mail)


hi
i have this code :
Expand|Select|Wrap|Line Numbers
  1.         MailMessage myMail = new MailMessage("mail@mail.com", "mail@mail.com", "My Report.", "See the file.");
  2.         SmtpClient myccc = new SmtpClient("localhost");
  3.         myccc.Credentials = CredentialCache.DefaultNetworkCredentials;
  4.         myccc.Send(myMail);
its just tell me this message :
Failure sending mail

<edit by mod: replaced email addresses with fake ones for your privacy>
Jan 29 '09 #1
Share this Question
Share on Google+
19 Replies


Plater
Expert 5K+
P: 7,872
If you look at the details of the exception that is thrown you will see what SMTP command generated the error. that might tell you more about what went wrong.
Jan 29 '09 #2

P: 10
i even look at it but its not helping
please someone help me
i need it so quick
Jan 29 '09 #3

Expert 100+
P: 190
Do you have a SMTP service installed and running as a Windows Service on the same machine defined as "localhost"?
Jan 30 '09 #4

Plater
Expert 5K+
P: 7,872
Are you catching the exception as the base Exception or as an SmtpException?
The SmtpException will give you extended information about the failure.
Jan 30 '09 #5

P: 10
no i haven't SMTP runing

sooo i need help give me a solution
Jan 30 '09 #6

Plater
Expert 5K+
P: 7,872
Well if you don't have an smtp server running, how do you expect to connect to it?
Jan 30 '09 #7

P: 10
Well if you don't have an smtp server running, how do you expect to connect to it?
then how can i run this thing ??
Jan 30 '09 #8

Plater
Expert 5K+
P: 7,872
I can think of two ways:
Open up a command prompt (cmd)
and run:
net start "Simple Mail Transfer Protocol (SMTP)"

Or run services.msc and look for the SMTP service and start it.
Jan 30 '09 #9

P: 10
I can think of two ways:
Open up a command prompt (cmd)
and run:
net start "Simple Mail Transfer Protocol (SMTP)"

Or run services.msc and look for the SMTP service and start it.

I do like you said but its not working
i run in cmd : net start
then i run the code but the same problem
Jan 31 '09 #10

100+
P: 283
some more information would help as we can guess from the code but this may not always be correct as you may have just found the code and be trying to use it incorrectly

are you trying to send on a network that is using exchange servers?

are you trying to send from a specific smtp server?

if you are connecting to a smtp server where are you intending to get the logon details from as with exchange you can use your standard network credentials but I don't think you can with SMTP

I have sent some stuff via exchange so don't have a lot of experience with doing smtp but this information will help clarify things a bit
Feb 1 '09 #11

P: 10
so i don't understand what are you mean exactly
but if you have another code than can i send an email please
tell me what is it
Feb 1 '09 #12

100+
P: 283
I haven't got an exchange server at home to work out the code but try having a look at this thread -

http://bytes.com/groups/net-asp/6651...-server-2007-a

if you have any problems I will try setting something up to work it out.
Feb 2 '09 #13

100+
P: 283
also you are pointing to your SMTP server as ' localhost ' which will redirect back to your PC, if you check the code you will see that it will usually point to a server running either exchange or an SMTP server, to confirm if it is runnning smtp you could try using telnet on port 25 unless it is set up for a different port
Feb 2 '09 #14

vekipeki
Expert 100+
P: 229
If you are making a WinForms app, you can do it using MAPI, and use MS Outlook (or other mail client) to send your mails.

Google for ".NET MAPI" (e.g. http://www.codeproject.com/KB/IP/SendFileToNET.aspx).

This way you don't have to worry about the SMTP server, but rather pass the mail to Outlook, which will then use its own stored account settings.
Feb 2 '09 #15

P: 10
OK man thanks a lot, this will help
i wish you a good luck in your life
Feb 2 '09 #16

100+
P: 283
only problem with using outlook is that 2003 pops up a stupid message asking if you want to allow the email due to a security patch

you can bypass this by either using sendkeys to send Alt + S to send it or using a third paty dll or similar but unfortunately all the one's I have seen were quite expensive.
Feb 2 '09 #17

100+
P: 283
looking at the code I might be incorrect as the stuff I was using previously was using the office interop stuff so I might have to try that code out.

Thanks
Feb 2 '09 #18

Plater
Expert 5K+
P: 7,872
I use outlook without poping up security prompts.
The prompt only pops up if you attempt to do a READ on any values.
If you only do writes, it won't popup.
As dumb as that sounds.
Feb 2 '09 #19

100+
P: 283
sounds odd, I was trying to create a message object , set the to and from etc and then send it so I am not fully sure what you mean by ' read ' but the code on the link looks quite different so I will have to have a look and see how it works
Feb 2 '09 #20

Post your reply

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