Link to home
Start Free TrialLog in
Avatar of claracruz
claracruz

asked on

SMTP email using c#

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
Avatar of apresto
apresto
Flag of Italy image

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
http://www.codeproject.com/dotnet/SystemWeb_Mail_SMTP_AUTH.asp

this code demonstrated how to incorporate username and password
Avatar of harshits
harshits

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
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
Avatar of claracruz

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of harshits
harshits

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial