notification Email by Upload

Discussion in 'Getting started' started by Peet, Feb 23, 2018.

  1. Hi. I just started an internship. my boss want me to programm a uplaod function for a website. it´s done, it works. now he want to get a email everytime a upload happens. i can´t figure out, why my code is crashing. everytime it says uncatched exception but i catched it. please help me. here the code:


    public void sendMail(
    string absender = "[email protected]",
    string empfaenger = "[email protected]",
    string betreff = "test",
    string nachricht = "testinhalt",
    string server = "smtp.mail.yahoo.com",
    int port = 465,
    string user = "[email protected]",
    string passwort = "testpassword")
    {
    MailMessage Email = new MailMessage();
    Email.From = new MailAddress(absender);
    Email.To.Add(empfaenger);
    Email.Subject = betreff;
    Email.Body = nachricht;
    SmtpClient MailClient = new SmtpClient(server, port);
    try
    {
    MailClient.Send(Email);
    }
    catch (SmtpFailedRecipientsException ex)
    {
    for (int i = 0; i < ex.InnerExceptions.Length; i++)
    {
    SmtpStatusCode status = ex.InnerExceptions.StatusCode;
    if (status == SmtpStatusCode.MailboxBusy ||
    status == SmtpStatusCode.MailboxUnavailable)
    {
    Console.WriteLine("Delivery failed - retrying in 5 seconds.");
    System.Threading.Thread.Sleep(500);
    MailClient.Send(Email);
    }
    else
    {
    Console.WriteLine("Failed to deliver message to {0}",
    ex.InnerExceptions.FailedRecipient);
    }
    }`enter code here`
    }
    try
    {
    MailClient.Send(Email);
    }
    catch (SmtpException ex)
    {
    Console.WriteLine("Fehler beim Senden der E-Mail\n\n{0}", ex.Message);
    }
    Console.ReadKey();
    if (user.Length > 0 && user != string.Empty)
    {
    MailClient.Credentials = new System.Net.NetworkCredential(user, passwort);
    MailClient.EnableSsl = true;
    }MailClient.Send(Email);
    }
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Try using port 587 without SSL disabled. And what was the exact error message?
     
  3. martino

    martino DiscountASP.NET Staff

    Try using localhost as the SMTP service and no SMTP authentication required.
     
    RayH likes this.
  4. Thank you alot guys. I found it. Yahoo itself is the Problem. It blocked my emails
     
    martino and RayH like this.

Share This Page