0

HI I developed an application to generate a report and the generated report should be emailed to the address given in the config file . Andmy code sends email to outlook only and i as in the live environment there wont be any outlook i want to send it in general . How can i achive this?

public void DCCEmailSetup(DateTime dateRunReport, string path, string messager)
{
    toEmailSetup = ConfigurationManager.AppSettings["To mailid"];
    fromEmailSetup = ConfigurationManager.AppSettings["From mailid"];

    try
    {
        var message = new MailMessage();
        message.To.Add(toEmailSetup);
        message.Subject = " Report generated " + dateRunReport;
        message.From = new MailAddress(fromEmailSetup);
        try
        {
            message.Attachments.Add(new Attachment(path));
            message.Body = messager;
        }
        catch (Exception e)
        {
            throw ;
        }

        var smtp = new SmtpClient(" ");
        smtp.Send(message);
    }   

    catch (SmtpException ex)
    {
        throw new ApplicationException
          ("SmtpException has occured: " + ex.Message);
    }

}
Abdul Munim
  • 18,869
  • 8
  • 52
  • 61
62071072SP
  • 1,963
  • 2
  • 19
  • 38
  • you may consider configuring your SmtpClient instance! See http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx for further details on MSDN or http://stackoverflow.com/questions/2916841/send-mail-in-asp-net for a nice example on this topic. – Pilgerstorfer Franz Dec 21 '11 at 11:26
  • Sorry, I'm a little lost, do you mean your live environment has no access to your Exchange server? –  Dec 21 '11 at 11:26
  • 2
    Just a tip; don't use "throw e" in your catch block - you are losing the stack trace of the caught exception. Use "throw" instead. – Chris McAtackney Dec 21 '11 at 11:27
  • Yes live environment has no exchange server . – 62071072SP Dec 21 '11 at 11:29

1 Answers1

1

If your live environment has no access to the Exchange server it will need access to a relay or something capable of forwarding messages to your Exchange/email server, otherwise no emails can be sent. Sorry :(