Для своего проекта silverlight я создаю новостную рассылку, которую можно отправить через определенную страницу.
Для этого у меня есть служба новостной рассылки, которую можно посмотреть здесь:
public bool SendMail(string emailTo, string emailFrom, string msgSubject, string msgBody)
{
bool success = false;
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(emailFrom);
msg.To.Add(new MailAddress(emailTo));
msg.Subject = msgSubject;
msg.Body = msgBody;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; // Replace with your servers IP address
smtp.Port = 465;
smtp.EnableSsl = false;
smtp.Send(msg);
success = true;
}
catch(Exception e)
{
success = false;
}
return success;
}
И я прошу службу отправить письмо со следующим кодом:
public partial class Nieuwsbrief : UserControl
{
IEnumerable<Inschrijvingen> ingeschrevenen = null;
public Nieuwsbrief()
{
InschrijvingenServiceClient personclient = new InschrijvingenServiceClient();
personclient.getInschrijvingenCompleted += new EventHandler<getInschrijvingenCompletedEventArgs>(personclient_getInschrijvingenCompleted);
personclient.getInschrijvingenAsync();
InitializeComponent();
}
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
NieuwsbriefServiceClient client = new NieuwsbriefServiceClient();
//foreach (Inschrijvingen person in ingeschrevenen)
//{
client.SendMailAsync("test@gmail.com", "nieuwsbrief@ondernemersaward.be", txtSubject.Text, txtContent.Text);
//}
client.SendMailCompleted += new EventHandler<SendMailCompletedEventArgs>(client_SendMailCompleted);
}
void personclient_getInschrijvingenCompleted(object sender, getInschrijvingenCompletedEventArgs e)
{
ingeschrevenen = e.Result;
}
void client_SendMailCompleted(object sender, SendMailCompletedEventArgs e)
{
if (e.Error != null)
txtContent.Text = "Mail has NOT send!" + e.Error.ToString();
else
MessageBox.Show(e.Result.ToString());
}
}
Однако, когда я нажимаю btnSubmit
, ничего не происходит, пока я не выключу сервер, а затем получу следующую ошибку:
Mail has NOT send!System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
--- End of inner exception stack trace ---
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at OndernemersAward.NieuwsbriefServiceReference.NieuwsbriefServiceClient.NieuwsbriefServiceClientChannel.EndSendMail(IAsyncResult result)
at OndernemersAward.NieuwsbriefServiceReference.NieuwsbriefServiceClient.OndernemersAward.NieuwsbriefServiceReference.NieuwsbriefService.EndSendMail(IAsyncResult result)
at OndernemersAward.NieuwsbriefServiceReference.NieuwsbriefServiceClient.OnEndSendMail(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
Надеюсь, кто-нибудь может мне помочь, спасибо :)