system.net.mail not sending out mail

I recently upgraded from a 2.0 framework to 3.5 using c#.  When I upgraded, I needed to change the way I was using MailMessage.  But now for some reason it doesn't work.  Am I missing something?
Below is my code:

using System.net.Mail;

MailMessage msg = new MailMessage();
msg.To.Add(toList);
msg.CC.Add(ccList = null ? "" : ccList);
msg.From = new MailAddress(fromList);
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHTML = true;

SmtpClient smtp = new SmtpClient(smtpServer);
smtp.Send(msg);

I'm passing all the value from my web.config file inside AppSettings.

What am I doing wrong? Am i suppose to add anything else in my web.config file?

TIA!

0
newbie_2007
11/14/2008 4:37:22 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

7 Replies
752 Views

Similar Articles

[PageSpeed] 4

Try

smtp.usercredentials=true; 

HTH,

-Prashant 

0
RutuPrash
11/14/2008 5:25:43 AM

try this,

 

Imports System.Net.Mail
     
 Dim Msg As MailMessage = New MailMessage()
        Dim MailObj As New SmtpClient("your smtp server name")


        Msg.From = New MailAddress("from@abcd.com")


        Msg.To.Add(New MailAddress("to@abcd.com")


        Msg.CC.Add(New MailAddress("cc@xyz.com")


        Msg.Subject = "Subject"


        Msg.IsBodyHtml = "True"
        Msg.Body = "Mail content "

        MailObj.UseDefaultCredentials = True
        MailObj.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

        MailObj.Send(Msg)

0
fanindrabhortakke123
11/14/2008 5:37:43 AM

 Why not store the mail settings in the web.config instead of the appsetting...

 

  <system.net>
    <mailSettings>
      <smtp from="">
        <network userName="" password="" host="" port="" />
      </smtp>
    </mailSettings>
  </system.net>

0
Natural
11/14/2008 5:45:30 AM

 

Hi newbie_2007,
smtp.UseDefaultCredentials = true;
  1. Add the above to your code.
  2. Put your code within try catch block.
  3. Please post the Exceptions you get.
 Thanks
 
Sincerely,
Mahesh Sundar
Microsoft Certified Professional
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
0
maheshin
11/14/2008 5:48:06 AM
Which operating system are you using
Regards
Karan Gupta

For .net,Javascript and Sql server articles and interview question visit


http://guptakaran21.googlepages.com/main
0
karang
11/14/2008 5:53:45 AM

Hi

copy the following code.. its working for my gmail account 

in web.config

<system.net>
  
    <mailSettings>
      <smtp from="youremail@gmail.com">
        <network host="smtp.gmail.com" port="587" userName="youremail" password="xx" defaultCredentials="false"/>
      
      </smtp>
    </mailSettings>
  </system.net>
 

 

In code behind ( on button click)

 Dim smtp As New System.Net.Mail.SmtpClient()
        Dim smail As New System.Net.Mail.MailMessage
        smail.To.Add(New System.Net.Mail.MailAddress("emailtowhomyouwanttosend@yahoo.com "))
        smail.From = New System.Net.Mail.MailAddress("youremail@gmail.com", "Visit me")
        smail.Subject = "hiii"
        smail.IsBodyHtml = "true"
        smail.Body = "HELLO THERE"
        smtp.EnableSsl = True
        smtp.Send(smail)

It will work for sure..

Good Luck

or check this post

http://forums.asp.net/t/1337021.aspx

0
yasserzaid
11/15/2008 2:07:43 PM

the problem is solved.  There was something wrong with our mail server.  Thanks everyone for your help.  Much appreciated!!

0
newbie_2007
11/18/2008 1:25:32 AM
Reply:

Similar Artilces:

System.web.mail to System.net.mail
I converted a asp.net web app from VS 2003 to VS 2005. i now get error message when i build it  stating system.web.mail  is obsolute,  use system.net.mail i redefine to system.net.mail but now i get other error message such as smtpMail does not exist in the current context. cannot implicitly convert type string to System.Net.Mail.MailAddress   so System.Web.Mail want work in ASP.net web app convert to VS 2005 running on framework 2.0?           because if i change to System.Net.Mail  i am ...

.net 2 beta 2 - System.Net.Mail
Hi guysI'm using the System.Net.Mail namespace in .net version 2, beta 2, to send out some HTML formatted e-mails.However, for some reason when the e-mail are sent out some of the full stops from the e-mail are removed.For example, part of the e-mail contains this code<img src="http://www.avonandsomerset.police.uk/images/grey_box_bottom.gif" alt="">But this is what the code is like when the e-mail source code is viewed<img src="http://www.avonandsomerset.police.uk/images/grey_box_bottomgif" alt="">Is this a known bug in beta 2? If so, where can I view a list of known bugs an...

Help for Visual web dev isolate system.web.mail to system.net.mail
Hi all,  I'm new user to visual web developer express software. Laterly i found this application isolate quite some of the component namespace, like system.web.mail to net.mail. I not well understand how system.net.mail functional?? Does it act same as system.web.mail?? My coding below: change system.web.mail to system.net.mail which causing a lot error... *****Can anybody correct me or advise me how to make this code work in system.net.mail?????? <%@import Namespace="System.net.Mail" %> <script runat="server">    Public FromAddress As String = "" .......

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

System.Web.Mail vs System.Net.Mail
Hi AllI was using System.Web.Mail in an application on our test server.  That worked fine.  I never had to specify a server or change any settings.  It just works.  Whatever settings the server has set up are used.  This is great.I saw that System.Web.Mail has been deprecated, so I'm trying to use System.Net.Mail.  I'm having a problem.  Net.Mail doesn't use whatever settings Web.Mail used.  I can't send e-mail with Net.Mail.  I see several people use the web.config file to set the server up, but I can't get that to work. I jus...

Changing System.Web.Mail to System.Net.Mail
I am trying to learn ASPI have been using the Visual Web Developer 2005I have the following line that I can not work out how to convert.<%Dim FromForm As String = "Mail@Myname.co.uk"Dim ToMe As String = "Me@myname.co.uk"Dim FormSubject As String = "Contact Infomation"Dim EmailText As String = "Blar Blar Blar"System.Web.Mail.SmtpMail.Send(FromForm,ToMe,FormSubject,EmailText)%>It tells me that I cannot use System.Web.Mail any more and should use System.Net.Mail. I have been unable to work out what the new code should be to get it to work.The Language is VBCan anyone tell me how to change...

switching from system.web.mail to system.net.mail
I have been converting my code from system.web.mail to system.net.mail.  I have been able to convert the to, from, cc, and message body to the new format easily but...my question is how do i convert this into system.net.mail format?SmtpMail.SmtpServer = "server";                SmtpMail.Send(mail);Would this be the solution?SmtpClient client = new SmtpClient("server");                client.Send(mail); Here's a full example of how to per...

Migrating from System.web.mail to System.net.mail
Hi Every1,I've recently used the System.web.mail to send mail, using the IIS's smtp server.Doing this, i didn't really need to do anything in the web.config file or give any special parameters to the client. It just assumed i was working with my very own smtp service that came with the IIS and everything worked fine.Now i migrated to System.net.mail and now i need to insert my smtp service's host location under <system.net> in the web.config file.However, i don't know what to write there so the client will use my smtp sevice (host="localhost" doesn't work)can any1 help me on this one?t...

difference between System.Web.Mail and System.Net.Mail
What is difference between System.Web.Mail and System.Net.Mail  namespace?What is use of both ? System.Web.Mail was in .NET Framework v1.1System.Net.Mail is in .NET Framework v2.0 and greaterSame use, although there is more functionality in System.Net.Mail since it is a later version of the framework. Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!  What All-Star said. I assume the reason it was moved to a different namespace is because the internet is actually a suite of technologies: e-mail, ftp, http (web), etc. E-mail and...

Working with System.Web.Mail but not with System.Net.Mail
Hi, i am having trouble sending e-mails using System.Net.Mail namespace while there is no problem with System.Web.Mail. I am  using remote smtp server with no authentication.  My code as shown below:1 try2 {3 MailMessage message = new MailMessage();4 message.BodyFormat = MailFormat.Html;5 message.To = "admin@mydomain.com";6 message.From = "test@mydomain.com";7 message.Subject = "Test Smtp";8 message.Body = "TestMail 123";9 10 SmtpMail.SmtpServer = "mail.mysmt...

Converting from System.Web.Mail to System.Net.Mail
Hi there, I'm from Argentina. I've converted System.Web.Mail (code is underlined) to System.Net.Mail (code is Bold) . I'd like to know if it's correct. Thanks !!public uint enviar()        {            try            {                // Abrir el archivo que contiene el template del HTML.                // Envia el mail con el HTML.&nbs...

About: how can i send a MIME(Text und Html Format) Mail by System.Net.Mail und .Net 2.0
Helle to all, I hope that someone can help me. I need to implement a programm to send newsletters. The newsletter Format can be Html, Text and MIME(Html and Text). when using CDONTS library man can set MailFormat = MIME. But i use System.Net.Mail and there are only text or html Format. Can someone tell me how can i use System.Net.Mail to send a MIME Mail? Thanks Best Regards Pinsha perhaps this link can help:  http://systemnetmail.com/faq/3.1.3.aspxIn this world there are 10 types of people, those that know binary and those who don't....

Problem with difference between System.Web.Mail and System.Net.Mail in using attachments
I have a web .Net app which sends emails with attachments.  After the email is sent I clean up aftermyself and delete the attachments from disk.   In upgrading to .Net 2  I changed the email logic from using system.web.mail to system.net.mail  (of course vs is telling me system.web.mail is obsolete).In .Net 1.1,  the files deleted with no problem but in .Net 2 when I attempt to delete  I receive The process cannot access the file ...' because it is being used by another process. If I change the code back to using system.web.mail I can delete the file...

What additional advantage we get through System.net.mail over the old system.web.mail?
What additional advantage we get through System.net.mail over the old system.web.mail?Is it needed to configure the smtp server? Plz tell me the steps to develop the email sending facility in our applicationSwati Jain Take a look at www.systemnetmail.com.JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue....

Web resources about - system.net.mail not sending out mail - asp.net.web-forms

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

Facebook Sending Perez Hilton More Traffic than Google, Driving 3.3% of All US Traffic to Video Sites ...
For media companies evaluating their Facebook marketing strategy , here’s an interesting sign of the times: web analytics firm Hitwise is reporting ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the ...
Get Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the App Store. See screenshots and ratings, ...


Cynthia McKinney - responds to Obama on sending troops into Afghanistan - Debate Answer - YouTube
Cynthia McKinney, Green Party Presidential candidate, responds to Barack Obama on his support for sending troops into Afghanistan. Based on his ...

Great-grandmother 'would die' before sending kids to Italy
Great-grandmother 'would die' before sending kids to Italy

Resources last updated: 12/16/2015 2:46:50 PM