Solved

SMTP email using c#

Posted on 2006-07-17
8
1,680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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