How can is send an email without user interaction?

EwoudvdWerfEwoudvdWerf USMember ✭✭✭

I have seen and read some simular posts with the same question, but none of them helped, i wan't to send an email to my email without the user to do anything, i have my own mail service (...@ewoudwerf.com) so maybe that helps to

Best Answer

  • VladimirDjordjevicVladimirDjordjevic US ✭✭
    Accepted Answer

    Hi,

    this should work.
    Just configure server parameters.

    `

            //define mail
                        MailMessage mail = new MailMessage();
                        SmtpClient SmtpServer = new SmtpClient("your smtp mail server");
                        mail.From = new MailAddress("[email protected]");
                        mail.To.Add("[email protected]");
                        mail.Subject = "your mail subject";
                        mail.Body = "this is my email";
                    //if you want to send an attachment just define filename
            System.Net.Mail.Attachment attachment;
                        attachment = new System.Net.Mail.Attachment(filename);
                        mail.Attachments.Add(attachment);
            //end email attachment part
    
                        SmtpServer.Port = 587;
                        SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                        SmtpServer.EnableSsl = true;
                        ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) {
                            return true;
                        };
                        SmtpServer.Send(mail);
    

    `

Answers

  • VladimirDjordjevicVladimirDjordjevic USMember ✭✭
    Accepted Answer

    Hi,

    this should work.
    Just configure server parameters.

    `

            //define mail
                        MailMessage mail = new MailMessage();
                        SmtpClient SmtpServer = new SmtpClient("your smtp mail server");
                        mail.From = new MailAddress("[email protected]");
                        mail.To.Add("[email protected]");
                        mail.Subject = "your mail subject";
                        mail.Body = "this is my email";
                    //if you want to send an attachment just define filename
            System.Net.Mail.Attachment attachment;
                        attachment = new System.Net.Mail.Attachment(filename);
                        mail.Attachments.Add(attachment);
            //end email attachment part
    
                        SmtpServer.Port = 587;
                        SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                        SmtpServer.EnableSsl = true;
                        ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) {
                            return true;
                        };
                        SmtpServer.Send(mail);
    

    `

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    @VladimirDjordjevic thanks this works perfectly!

  • iManchaiMancha ZAMember ✭✭

    Does this work on iOS as well?

Sign In or Register to comment.