Solved

SMTP email using c#

Posted on 2006-07-17
8
1,663 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get Reply from SSIS to intranet site when finished 3 34
SQL best practice question 3 36
Connection String 16 43
Where can I ask about my ASP.NET MVC project? 6 23
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

23 Experts available now in Live!

Get 1:1 Help Now