locked
Send Email RRS feed

  • Question

  • User-1404740798 posted
    public ActionResult About()
            {
                return View();
            }
            [HttpPost]
            public ActionResult About(EmailViewModel email)
            {
    
                try
                {
    
                    SmtpClient client = new SmtpClient("server host", 25);
                    client.UseDefaultCredentials = false;
                    client.EnableSsl = true;
                    client.Credentials = new NetworkCredential("Server UserName", "Password");
                    
    
                    MailMessage mail = new MailMessage();
    
    
                    mail.To.Add("email Address");
                    mail.From = new MailAddress("email Address");
                    mail.Subject = email.Subject.ToString();
                    mail.Body = email.Contents.ToString();
                    mail.IsBodyHtml = true;
    
    
    
                    client.Send(mail);
    
                    ViewBag.Status = "success!";
    
                }
                catch (Exception ex)
                {
                    ViewBag.Status = "false!";
                }
                return View();
            }

    You have successfully implemented the Mail Transfer Service.

    Successful mail transfer may result in a message called "success".

    I got a "success" message, but no mail was sent to my email.

    Can you tell me how to fix it?

    Thursday, November 1, 2018 4:55 AM

All replies

  • User1520731567 posted

    Hi slkim,

    Actually,I have not found any problems in your code.

    I suggest you could check your mailbox.

    Does it treat your mail as spam?

    Best Regards.

    Yuki Tao

    Friday, November 2, 2018 7:39 AM
  • User-1404740798 posted

    I want to use my server without using Google.

    Thursday, November 8, 2018 12:33 AM
  • User-42918493 posted

    I'm sending mail using sendgrid... Refer below code

    MailMessage mail = new MailMessage();
                    mail.To.Add(l_ToMail);
    
                    mail.From = new MailAddress("care@parentsalarm.com.com", l_SenderName);
                    mail.CC.Add(l_ToMailCC);
                    mail.Subject = l_MailSubject;
                    mail.Body = l_msgBody;
                    mail.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "smtp.sendgrid.net";
                    smtp.Port = 587;
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = new System.Net.NetworkCredential("username", "password");
                    smtp.EnableSsl = true;
                    smtp.Send(mail);

    Thursday, November 8, 2018 6:08 AM
  • User-474980206 posted

    to help we would need to know more about the actual smtp host. maybe the mail is still in the pickup folder. maybe the mail was seen as spam.

    Thursday, November 8, 2018 4:15 PM
  • User753101303 posted

    Hi,

    "Success" or "Success!" ? Make sure the message you see is the one that comes from this place.

    If you are 100% sure you don't have an exception technically speaking the message is sent but it is still possible that :
    - it is blocked and considered as spam (can happen for small test messages, try to use a significant amount of text)
    - check the client side "Junk" folder
    - the mail address could be wrong

    Thursday, November 8, 2018 4:33 PM