Send Email Error #2

Hi I have set up a asp page to send emails. All works well on my local machine but when I put it on the server I get a "Failure sending mail" error.

Web config:

  <system.net>
        <mailSettings>
            <smtp>
                <network
                     host="smtp.thehostname.com"
                     port="587"
                     userName="thename@thesite.com"
                     password="thepassword" />
            </smtp>
        </mailSettings>
    </system.net>

Which is under the configuration element

The Class:

using System.Net.Mail;

public class SendEmail
{
	public SendEmail()
	{
	}

   public String send(string ToAddress, string fromAddress, string subject, string body)
    { 
        try
        {
            MailMessage message = new MailMessage(fromAddress, ToAddress);
            message.Subject = subject;
            message.Body = body;
            message.IsBodyHtml = false;
            SmtpClient smtp = new SmtpClient();
            smtp.Send(message);
        }
        catch (Exception ex)
        {
            return ex.Message;
        }

        return "good";
   }
}

Why would it work on my local machine but not the server?

Cheers

Cam.

 

 

0
mrwelcam
3/8/2009 7:08:54 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

10 Replies
696 Views

Similar Articles

[PageSpeed] 3

 can you add this line

smpt.Credentials = CredentialCache.DefaultNetworkCredentials;
before  
smtp.Send(message);
and try again. 
 

 


Mark as an answer if it helps.
0
almargob
3/8/2009 9:29:54 PM

Thanks for getting back to me. I put it in and am still getting the errer. Can you tell me what that does.

Cheers

Cam. 

 

 

0
mrwelcam
3/8/2009 9:54:57 PM

The exact problem is almost certainly due to the server settings you are now using.

The best way to diagnose email errors is to print out the full error stack. The exact problem is very rarely shown in the top level error.

Try the following in the catch block:

 

System.Text.StringBuilder sb = new System.Text.StringBuilder();
Exception currentEx = ex;
While(currentEx !=null)
{
  sb.Append("Exception Details - ");
  sb.Append(currentEx.Message);
  sb.Append(Environment.NewLine);
  sb.Append(currentEx.StackTrace);
  sb.Append(Environment.NewLine);
  sb.Append(Environment.NewLine);
}
return sb.ToString();
Give me a shout if that fails, I haven't got Visual Studio on this PC.

Fran Hoey - ASP.NET Freelancer - BlueJumper.com
0
Dinkle
3/8/2009 10:20:15 PM

I keep getting a out of memory exception


 

Exception of type 'System.OutOfMemoryException' was thrown.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Source Error:

Line 42:                 sb.Append(currentEx.Message);
Line 43:                 sb.Append(Environment.NewLine);
Line 44:                 sb.Append(currentEx.StackTrace);
Line 45:                 sb.Append(Environment.NewLine);
Line 46:                 sb.Append(Environment.NewLine);

0
mrwelcam
3/8/2009 11:08:00 PM

Sorry, my fault. I set you up an infinate loop!

Try this:

 

System.Text.StringBuilder sb = new System.Text.StringBuilder();
Exception currentEx = ex;
While(currentEx !=null)
{
  sb.Append("Exception Details - ");
  sb.Append(currentEx.Message);
  sb.Append(Environment.NewLine);
  sb.Append(currentEx.StackTrace);
  sb.Append(Environment.NewLine);
  sb.Append(Environment.NewLine);

  currentEx = currentEx.InnerException;
}
return sb.ToString();
 
Fran Hoey - ASP.NET Freelancer - BlueJumper.com
0
Dinkle
3/9/2009 9:39:50 AM

Hi,

Set the  network credentials for sending email 

let us know what error u are getting after setting credentials

Best Reagrds 


life is name of learning!
Mark as an answer if it helps
0
Rameezwaheed
3/9/2009 10:13:50 AM

From the port it seems you are using gmail server to send emails

hence it works on your local machine but many providers block connections to outside server that's why it does not work there


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
3/9/2009 10:18:56 AM

Web config:

  <system.net>
        <mailSettings>
            <smtp>
                <network
                     host="smtp.thehostname.com"
                     port="587"
                     userName="thename@thesite.com"
                     password="thepassword" />
            </smtp>
        </mailSettings>
    </system.net>

 

Muddasar Khan one thing more i want to  clear myself that defining mailsettings in web.config file . how we can access these credentials inside code behind . do we set the netwrok credebtails only here in web.config file by default accessed inside code kindly ? clear to me in this regard.

Best Reagrds


life is name of learning!
Mark as an answer if it helps
0
Rameezwaheed
3/9/2009 10:31:11 AM

Thanks everybody for getting back to me. I got in contact with my server and they told me i need to get through a proxy.

proxy.private.site.net:3123

How do I go about setting this up.

Cheers

Cam
 

0
mrwelcam
3/9/2009 10:40:44 AM

I've never done this before, but I think you can set it in your web.config as such:

 
<system.net>
		<defaultProxy enabled="true">
			<proxy proxyaddress="proxy.private.site.net:3123" />
		</defaultProxy>
  
Fran Hoey - Freelance Web Developer - BlueJumper.com
0
aspnet
3/9/2009 12:58:49 PM
Reply:

Similar Artilces:

After upgrading from 2 to 3, get error when sending email
Name: Chris Product: Thunderbird Summary: After upgrading from 2 to 3, get error when sending email Comments: I do all the "computer" stuff for my parents, and decided to upgrade from Thunderbird 2 to 3 since I was over. The upgrade process seemed to go quite well, but after upgrading, attempting to send an email resulted in a security error message. After spending 15 minutes hunting through settings, it look like unchecking "Security and Authentication" -> Use name and password fixed it. So while it otherwise looks like a well organized upgrade to a g...

Sending Email with Net.Mail (No Email, no error)
hi,i'm using the system.net.Mail namespace to send an email from my application. when i send, the application does not fire any exception, neither does it send the email to my account.below is the code i'm using  Dim mmailMessage As New Net.Mail.MailMessage Dim mFrom As New Net.Mail.MailAddress(mailFrom) mmailMessage.From = mFrom Dim ll As String = "myname@ourmail.com" mmailMessage.To.Add(ll) mmailMessage.Subject = "Talk Concerns" mmailMessage.Body = "Testing Concerns One Two" Dim ...

2.1.2
I recently moved three of my working DNN sites to a new server.  I discovered that after the move..NONE of my emails from the DNN sites work.  I get this error when I try to send an email through the bulk email feature:  ErrorCode: -2147467259Message: Could not access 'CDO.Message' object.InnerException: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040220): The "SendUsing" configuration value is invalid. --- End of inner exception stack trace --- at System.Runtim...

get a security error - get certificate
This has only happened with one person. In trying to send an email to time warner (not an issue I don't think) when he trys to add his signature he gets 'security error' you do not have a security certficate. Talk about being the wrong error for this one. any ideas? GW7sp2 On Wed, 10 Oct 2007 20:18:51 +0000, mark wrote: > This has only happened with one person. In trying to send an email to > time warner (not an issue I don't think) when he trys to add his signature > he gets 'security error' you do not have a security certficate. Talk >...

Converting classic to .NET 2 code, and .NET gets an error back from ADS?
 For future-proofing, our Internal Phone Directory is being moved onto our AD servers, and obviously we're using LDAP for queries.To get the phoneboook queries working, I adapted the current classic ASP code to use LDAP, and that works fine. However, we're wanting to move these pages to .NET, and that's where the problem comes in. Using the same basic logic from the Classic code (90% of its unchanged) to produce an LDAP query, I get the error  155 Unknown error (0x80005000)This is using the same website, and so the same credentials  - unless aspx pages run und...

SM 2.0 Can't Get Email, But Can Send Email
I've just installed SeaMonkey 2.0, imported all my old data, and started the new version. I have a couple of problems/questions: 1. I can send email, but when I click on the Get Msgs/Get All New Messages menu item, nothing happens. No status messages in the footer to show any activity, and the messages I can see in my webmail account inbox are not downloaded. If I start the old version it downloads the messages just fine. 2. When I start the email app, no folder is selected, so my Inbox emails don't appear in the right pane until I select the Inbox folder. I used to...

I can send email from my site, but I get an error when I try to send a cell phone TM.
From all that I can gather sending a TM is very much the same as sending an email. Only thing that changes is who it is being emailed to. That being said however I keep getting this error: Mailbox unavailable. The server response was: <'left out for security reasons'@vtext.com> No such user here at System.Net.Mail.Smtp  Any one know why?? chekmate:Any one know why?? Yep.  The account you tried to email to doesn't exist at the server you tried to send it to.  You got the wrong account, the wrong server or both. JeffPlease: Don't forget to click &...

Sending Email through System.Net.Mail is generating errors "Failure Sending mail
hi Sending Email through System.Web.Mail is working fine but System.Net.Mail is generating errors "Failure Sending mail  i treid in all possible ways but did't  pls help in giving a solution thanks & Regards vittal Maybe you can show us some code and post the exact error mesg as well (by looking at the value in ex.tostring)?My HomePage - www.findingsteve.net"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)Progress - "Never discourage anyone...who continually makes progress, no matter how slow." Plato System.Web.Ma...

Sending email error #2
Hi, I am getting "CDO Object error". I know many of you have already faced this error and solved it. So do I but now I am not able to solve it. I have done everything. I have given ASPNET account permission to send emails. I have also changed the relay settings. I restarted the IIS but still no use. Here is my simple code for sending emails: public int SendEmail(string emailTo, string message)         {             try             {   &nbs...

error in sending email #2
  Unable to read data from the transport connection: net_io_connectionclosed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.protected void Button1_Click(object sender, EventArgs e) {SmtpClient client = new SmtpClient();   MailAddress from = new MailAddress("makasu12@yahoo.com.sg");MailAddress to = ...

Error Sending Email from .NET
Hey there.Ive made a signup script that authenticates users email by sending an activation code to their email address. The problem im getting is the following...The server rejected one or more recipient addresses. The server response was: 503 This mail server requires authentication. Please check your mail client settings. Now Ive been told this can be sorted via settings on the server but Ive emailed my hosting providers and they cant/wont change these settings... so is there any way I can get around this from within ASP.NETI would really appreciate any and all suggestions. Many Regards ...

Get error when sending email
Since updating to SM 2.13.1 from SM 2.12.1, when I go to send an email I get an error to check my Temp file settings, this does not happen every time but quite often. I close the error and try to send again -sometimes the message is sent but some times I have to try three or four times. Any ideas? Error is below: Send Message Error Sending of message failed. Unable to open the temporary file C:\Docume~1\Jamess~1\locals~1\temp\nsmail.temp. Check your 'Temporary Directory' settings. JAS -- You either teach people to treat you with dignity and respect, or you don'...

error sending email #2
advance thanks to all, can't send email, error occur.  the error is as follows:System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: Relay error on mailstor for your ip - XXX.XXX.XX.XXX at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) can u tell me what is wrong with my code.                  ...

Email gets a send error but still goes into Sent folder. Sometimes successfully sends and sometimes doesn't
The error message we recieve sometimes on an employee's computer when sendi= ng mail reads "An error occured while sending mail. The mail server respond= ed: Resources temporarily unavailable - Please try again later. Please chec= k the message and try again" Thunderbird then proceeds to put the message in the Sent folder after hitti= ng OK, defeating the purpose of the error in my opinion. Whether or not it successfully sends is completely unknown to us unless the= person replies or the person it was emailed to is within our office; howev= er, when sending the email...

Web resources about - Send Email Error #2 - asp.net.getting-started

Email - Wikipedia, the free encyclopedia
is a method of exchanging digital messages from an author to one or more recipients. Modern email operates across the Internet or other computer ...

Houston schools in session in spite of threatening email - abc13.com
Houston ISD is sending parents across the school district automated phone calls, notifying them of a threat it received.

A single unread email could let hackers unleash havoc in a company’s network
... Zero hackers discovered they were able to penetrate the safety of a company using FireEye networking equipment with the help of a single email ...

Defense secretary admits "mistake" in using personal email for work - Videos - CBS News
In an interview you’ll see only on “CBS This Morning,” Defense Secretary Ashton Carter told Charlie D’Agata he didn't use the account for classified ...

Report: Ash Carter used personal email for some government business
CNN Report: Ash Carter used personal email for some government business CNN (CNN) The use of personal email to conduct government business ...

The Next Hillary Clinton? SecDef Ash Carter Conducted Official Gov’t Business On Personal Email Account ...
'The secretary believes that his previous, occasional use of personal email for work-related business ...

Consumers Look for More Targeted Email Personalization
More than 90 percent of marketers using email personalization have seen an increase in their email open rate and click-through rate (CTR).

Do These 5 Things Now To Have No Emails After The Holiday Break
... and return to an (almost) empty inbox in January. Breaks from work are refreshing, but returning to an inbox filled with hundreds of emails ...

How To Reduce Your Email Inbox After The Holidays
Are you overloaded by work emails? Then you are not alone. Research conducted by HR magazine and IBM entitled ‘The Reclaim Your Time’ survey ...

EMAIL MISHAP: Pentagon chief used private account in first months on job
EMAIL MISHAP: Pentagon chief used private account in first months on job

Resources last updated: 12/18/2015 8:52:03 PM