Solved

SMTP email using c#

Posted on 2006-07-17
8
1,657 Views
Last Modified: 2012-06-21
Hello experts,

I am trying to send emails via a web application. when i test it on my local machine, it works fine. But when I upload to the live server it doesn't. I am using the follwoing line to send;-

Utils.Mail.MailSender.SendMailMessage("Localhost", msgWithAttachment);

I got the following code off the internet somewhere;-

Response.Write(bthcu.Message + bthcu.StackTrace);

This outputs the following when the email is not sent;-
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for myemail@yahoo.co.uk at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Utils.Mail.MailSender.SendMailMessage(String SMTPServer, MailMessage message) in C:\VS2005Projects\EasyMailSender\EasyMailSender\MailSender.cs:line 83 at valuation.ImageButton1_Click1(Object sender, ImageClickEventArgs e) in c:\Inetpub\wwwroot\livesite\valuations\valuation2.aspx.cs:line 212
0
Comment
Question by:claracruz
8 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17120954
Hi claracruz,

You might need to use the server's name.  Also check if you need to authenticate against the mail server as i think this is whats happening, if so you need to add smtp fields

Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17120958
http://www.codeproject.com/dotnet/SystemWeb_Mail_SMTP_AUTH.asp

this code demonstrated how to incorporate username and password
0
 
LVL 3

Expert Comment

by:harshits
ID: 17121027
Hi claracruz

Here is code which I generally use in my asp.net applications

System.Web.Mail.MailMessage mm=new System.Web.Mail.MailMessage();
                  mm.To="tomailid";
                                     mm.From="From";
                  mm.Body="Hi, test";                  

System.Web.Mail.SmtpMail.SmtpServer="Name of the SMTP server name which your live server uses";

System.Web.Mail.SmtpMail.Send(mm);

Harshit Sheth
0
 
LVL 23

Expert Comment

by:apresto
ID: 17121063
this error:

The server response was: 5.7.1 Unable to relay for myemail@yahoo.co.uk

generally means that the server cannot reack the yahoo.co.uk domain - probably because you need to authenticate yourself as a sender - i dont think it is the code that is the problem
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Expert Comment

by:irps20001
ID: 17121353
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17121778
0
 
LVL 4

Author Comment

by:claracruz
ID: 17129436
kaliyugkaarjun ,
My code works on my local computer, I know the code is not the probelmAnd am using c#.


apresto ,
How do i  authenticate myself as a sender - i know its not a code problem as it works on my local machine. What I need to know is how to configure my webserver/smtp server to send emails

Many Thanks,

Clara
0
 
LVL 3

Accepted Solution

by:
harshits earned 500 total points
ID: 17136118
This seems to be the solution to your problem. Just check this...

http://www.mikepope.com/blog/DisplayBlog.aspx?permalink=1251&count=no


" A little googling to learn what the 5.7.1 error is, from which I deduce that the Exchange server is refusing to relay for anyone not in its domain. So I look again at the From and To addresses. Ok, well, one problem is that I misspelled the From address. A few more experiments, and I learn that our internal relay server will send only from and to addresses within our domain. (Or so it seems.)

Anyway, now it works.".....

Harshit Sheth
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now