I`m working with C# using the libraries
using System.Net.Mail;
using System.Windows;
I want to use the code in many places, ie. place A, place B, place C ...
when I use it at place A, it works and mails are sent from my application.
but when I use it at place B, place C ... nothing is sent and I get errors, I want to know how to solve it.
this is my class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Windows;
namespace Send_Mail_WPF_
{
class SendMail
{
private string fromAddress;
private string fromPassword;
private string toAddress;
private string msgSubject;
private string msgBody;
private string exchangeServer;
private int exchangeServerPort;
private bool error;
private MailMessage message;
SmtpClient client;
public SendMail(string fromMail, string toMail, string fromPass, string subject, string body)
{
error = false;
try
{
fromAddress = fromMail.ToString();
toAddress = toMail.ToString();
fromPassword = fromPass.ToString();
msgSubject = subject.ToString();
msgBody = body.ToString();
exchangeServer = @"smtp.tedata.net";
exchangeServerPort = 25;
initializeMessage();
setSMTPClient();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
errorFound = true;
}
}
public bool errorFound
{
set
{
error = value;
}
get
{
return error;
}
}
private void initializeMessage()
{
message = new MailMessage(fromAddress, toAddress);
message.Subject = msgSubject;
message.Body = msgBody;
message.IsBodyHtml = false;
}
private void setSMTPClient()
{
try
{
client = new SmtpClient(exchangeServer, exchangeServerPort);
client.EnableSsl = false;
client.Credentials = new NetworkCredential(fromAddress, fromPassword);
MessageBox.Show("From" + message.From.ToString());
message.From = new MailAddress("[email protected]");
MessageBox.Show("From" + message.From.ToString());
Application.Current.Shutdown();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
errorFound = true;
}
}
public void sendMessage()
{
try
{
client.Send(message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
errorFound = true;
}
}
}
}
I think the problem is in the exchange server, but I don`t know how to over come this.
EDIT:
ERROR I get from any location rather than place A