Im trying to send and Email with SmtpClient at the yahoo smtp server
"smtp.mail.yahoo.com", 587
The first time trying, I got an email telling me to change my account settings to allow smtp requests to work, but after doing that, the mailbox is unavailable.
SendMail method:
public void SendMail(string name, string from, string to, string subject, string content)
{
try
{
using (var mail = new MailMessage())
{
const string email = @"[email protected]";
const string pw = "***";
var login = new NetworkCredential(email, pw);
mail.From = new MailAddress(from);
mail.To.Add(new MailAddress(to));
mail.Subject = subject;
mail.Body = content;
mail.IsBodyHtml = true;
try
{
using (var client = new SmtpClient("smtp.mail.yahoo.com", 587))
{
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = login;
client.Send(mail);
}
}
finally
{
mail.Dispose();
}
}
}
catch(Exception ex)
{
}
}
Action:
[HttpPost]
public ActionResult ContactSend(Mail mail)
{
if(ModelState.IsValid)
{
var toAdress = @"[email protected]";
var fromAdress = mail.Email;
var subject = mail.Betreff;
var name = mail.Name;
var content = new StringBuilder();
content.Append("Name: " + name + "\n");
content.Append("Email: " + fromAdress + "\n\n");
content.Append(mail.Content);
SendMail(name, fromAdress, toAdress, subject, content.ToString());
}
return RedirectToAction("Kontakt", "Home");
}
Checked all the login information and since i got an email from yahoo the first time i tried it they seem to work.
Exception:
- Response {System.Web.HttpResponseWrapper} System.Web.HttpResponseBase {System.Web.HttpResponseWrapper}
- ex {"Postfach nicht verfügbar. Die Serverantwort war: Request failed; Mailbox unavailable"} System.Exception {System.Net.Mail.SmtpException}
- Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} HResult -2146233088 int HelpLink null string
- InnerException null System.Exception Message "Postfach nicht verfügbar. Die Serverantwort war: Request failed; Mailbox unavailable" string Source "System" string StackTrace " bei System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)\r\n bei System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)\r\n bei System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)\r\n bei System.Net.Mail.SmtpClient.Send(MailMessage message)\r\n bei Makler.Controllers.HomeController.SendMail(String name, String from, String to, String subject, String content) in C:\Users\Joshua\source\repos\Makler\Makler\Controllers\HomeController.cs:Zeile 90." string StatusCode MailboxUnavailable System.Net.Mail.SmtpStatusCode
- TargetSite {Void CheckResponse(System.Net.Mail.SmtpStatusCode, System.String)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
- Static members
- Non-Public members
- this {Makler.Controllers.HomeController} Makler.Controllers.HomeController