Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mikkel 143 posts 365 karma points
    Mar 14, 2019 @ 10:28
    mikkel
    0

    Can email be dynamic so it can find email of the owner of the website it self

    How do I set the smtp "from" to the administrator mail of the page so I do not have to type it manually with the email password etc. it also send an email for the person who type in his email and that is wrong. It have to send an email to the owner of the site so he knows there is a message. what am i doing wrong there?

    Webconfig email settings

    <smtp deliveryMethod="Network" from="[email protected]">
                    <network host="smtp.gmail.com" port="587" enableSsl='true' defaultCredentials='false' userName="[email protected]" password="1234567890"/>
                </smtp>
    

    App settings i webconfig

       <!-- indstillinger for send mail -->
        <add key="SendEmailFrom" value="[email protected]"/>
        <add key="EmailPassword" value="1234567890"/>
        <add key="EmailEmne" value="Besked fra din hjemmeside"/>
    

    My controller

    private void SendMail(KontaktModel model)
            {
    
               var fraEmail = new MailAddress(ConfigurationManager.AppSettings["SendEmailFrom"]);
                var tilAdresse = new MailAddress(model.Email);
                string emne = ConfigurationManager.AppSettings["EmailEmne"];
                string body = model.besked;
    
                var besked = new MailMessage(fraEmail, tilAdresse)
                {
                    Subject = emne,
                    Body = body
                };
    
                try
                {
                    //Forbind til SMTP i webconfig
                    var smtp = new SmtpClient();
                    smtp.Send(besked);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft