Forum Xamarin Xamarin.Forms

Receive an email without the permission of the sender when using my app

Glorious18Glorious18 Member ✭✭✭

Dear friends

I designed an educational app to be used by my students.

It has a one time signup page, the first time a student registers his email to start using my app.

What I want is to receive from him/her an email/SMS without opening any email client program or SMS program and without the permission from him/her to send me the message that he/she registered and where the message includes the email of the student used in the registration process.

Can we do it?
Can you send me a sample simple project that does this task Please?

Thank you in advance for your cooperation

Best Answer

  • Glorious18Glorious18 Member ✭✭✭
    edited October 16 Accepted Answer

    Hi Jezh

    I just want to tell thank you for the code.
    One error was detected when the program was deployed on an emulator

    I searched the forums for a correction and found it and I fixed and tested the code and it worked perfectly

    I attach to my reply the modified code

    Another follow up favour please:
    Now that the mail is sent without user interaction, I want the user to be able to sign in and access the app when the email is sent successfully
    What I must add to the attached code to say that if the email is sent successfully, the user can enter and go the first page using the following statement:

    await Navigation.PushAsync(new HomePage());

    If the email is not sent because the user did not enter a correct email address, the user will not be given access to the HomePage

    `
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    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("majidov18", "MajidNahla2014");
            SmtpServer.EnableSsl = true;
            ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)
            {
                return true;
            };
            SmtpServer.Send(mail);`
    

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    What I want is to receive from him/her an email/SMS without opening any email client program or SMS program

    Sorry, I am confused with what said. How does the app send you information when the user hasn't opened your app yet?

    without the permission from him/her to send me the message that he/she registered and where the message includes the email of the student used in the registration process.

    Besides, I don't quite understand what you mean by above words. Could you please elaborate on that?

  • Glorious18Glorious18 Member ✭✭✭

    Good day Jezh

    The user will open my app and will fill in his/her email to enter and start using the app features
    once the submit (or sign up) button is pressed, an automatic email (if the user is connected to the internet for sure) must be received by me saying that a person whose email is [email protected] for example has registered and is using your app

  • Glorious18Glorious18 Member ✭✭✭

    `XAML



    C#
    using System.Net.Mail;
    using Xamarin.Forms;

    namespace XamarinFormsEmail
    {
    public partial class MainPage : ContentPage
    {
    public MainPage()
    {
    InitializeComponent();
    }

        void btnSend_Clicked(object sender, System.EventArgs e)  
        {  
            try{  
    
                MailMessage mail = new MailMessage();  
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
    
                mail.From = new MailAddress("[email protected]");  
                mail.To.Add(txtTo.Text);  
                mail.Subject = txtSubject.Text;  
                mail.Body = txtBody.Text;  
    
                SmtpServer.Port = 587;  
                SmtpServer.Host = "smtp.gmail.com";  
                SmtpServer.EnableSsl = true;  
                SmtpServer.UseDefaultCredentials = false;  
                SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "***********");  
    
                SmtpServer.Send(mail);  
            }  
            catch(Exception ex)  
            {  
                DisplayAlert("Faild", ex.Message, "OK");  
            }  
        }  
    }  
    

    }
    `

  • Glorious18Glorious18 Member ✭✭✭

    In this code, an email program or browser will open and a user will have the option of sending an email or not to me.

    This is what I do not want to happen. I want to be informed from the program as a notification/emasil/sms, ... that someone has started using my app when it is first run (after downloading it)

  • RHudsonRHudson CAMember ✭✭✭

    @Glorious18

    You should be handling all of the sign-up logic on your server. I assume you have a backend server, right?

    This is the algorithm I would follow:

    The user enters their email address (and perhaps full name ) and taps "Send". This data is posted to a web service.

    The web service looks up this email address in your database.
    Does this address exist yet?
    -yes > inform the user; perhaps add a 'Forgot Password" button
    -no > add the user to the database and email them a temporary (random) password. The app informs the user to check their inbox for the temporary password

    Display the Login page. The Login page will have 4 fields
    -Email address
    -Temporary password
    -New permanent password
    -Permanent password again for verification

    Use Local Storage to save a token (that your server provides upon successful login.
    When your app launches, check if there is a token saved (and has not expired)

    Is there a valid token?
    -yes > the app is unlocked and all feature are available
    -no > Display 2 buttons "Sign In" and "Sign Up". This handles both cases; brand new users and existing users who already have an account.

  • Glorious18Glorious18 Member ✭✭✭

    Dear RHudson,

    Thank you for the suggestion but I want the idea to be much simpler.

    No I don't have a server and what I need is just an email to be received as a notification when a user enters login info the first time he/she uses my app (sign-up page)

  • jezhjezh Member, Xamarin Team Xamurai

    For how to send email, you can check this thread: https://forums.xamarin.com/discussion/156807/send-picker-choice-to-email

  • Glorious18Glorious18 Member ✭✭✭

    Dear jezh,

    Thank you for the link. I tried it and it worked. I was able to send an email but this is not what I want.

    When I pressed "Send Email" button, a window opened asking me to open an email app as it is seen in the attached pictures and when the "Compose" message is displayed, I pressed the "Send" button to send the email.

    So in this method, the App user can decide NOT to send the email. I do not want this to happen. I want the email to be sent once the button is pressed in my App without opening the email app!

    Is it possible?

  • Glorious18Glorious18 Member ✭✭✭

    what you see in the above pictures is NOT what I want to happen

  • Glorious18Glorious18 Member ✭✭✭

    I am facing another problem:

    My app is crashing( closing) when in the login page I enter the registered email and password and a message is displayed to me as in the below picture

  • jezhjezh Member, Xamarin Team Xamurai

    My app is crashing( closing) when in the login page I enter the registered email and password and a message is displayed to me as in the below picture

    Could you please post the error log about this question?

  • Glorious18Glorious18 Member ✭✭✭

    No error log. It works fine without any error on the Emulator but crashing (closing) happens when the app is deployed and used on the mobile

  • Glorious18Glorious18 Member ✭✭✭

    But what about the email? is it possible to be done without the compose and send email window?

  • jezhjezh Member, Xamarin Team Xamurai

    Do you want to send an email without user interaction ,right?

    Then you can check this thread: https://forums.xamarin.com/discussion/comment/209294#Comment_209294

  • Glorious18Glorious18 Member ✭✭✭

    Hi Jezh

    Thank you for the link

    when i paste and modified the code to be executed when a command button is clicked, the word sender (object sender, X509Certificate ) was underlined in red
    saying that it was used before and cannot be used her

    private void OnButtonClicked2(object sender, EventArgs e)
    {..}

    ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain,

  • Glorious18Glorious18 Member ✭✭✭
    edited October 16 Accepted Answer

    Hi Jezh

    I just want to tell thank you for the code.
    One error was detected when the program was deployed on an emulator

    I searched the forums for a correction and found it and I fixed and tested the code and it worked perfectly

    I attach to my reply the modified code

    Another follow up favour please:
    Now that the mail is sent without user interaction, I want the user to be able to sign in and access the app when the email is sent successfully
    What I must add to the attached code to say that if the email is sent successfully, the user can enter and go the first page using the following statement:

    await Navigation.PushAsync(new HomePage());

    If the email is not sent because the user did not enter a correct email address, the user will not be given access to the HomePage

    `
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    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("majidov18", "MajidNahla2014");
            SmtpServer.EnableSsl = true;
            ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)
            {
                return true;
            };
            SmtpServer.Send(mail);`
    
  • Glorious18Glorious18 Member ✭✭✭
    edited October 16

    Another follow up favour please:

    Now that the mail is sent without user interaction, I want the user to be able to sign in and access the app when the email is sent successfully
    What I must add to the attached code to say that if the email is sent successfully, the user can enter and go the first page using the following statement:

    await Navigation.PushAsync(new HomePage());

    If the email is not sent because the user did not enter a correct email address, the user will not be given access to the HomePage

  • jezhjezh Member, Xamarin Team Xamurai

    I searched the forums for a correction and found it and I fixed and tested the code and it worked perfectly.

    Congrats. And thanks for your support for xamarin. :)

    In general, one problem, one thread. You can create a new thread for your follow up question.
    We are all willing to help you.

    Besides, could you please mark the useful reply as answered so that it will help others who have similar questions?
    Thanks in advance. :)

  • Glorious18Glorious18 Member ✭✭✭

    Many thanks for your appreciated help and assistance.
    I still have a problem about the crashing of the app on my SAMSUNG mobile.
    I will create a new post for it as you asked me.

    Best Regards
    Stay Safe and In Good Health

Sign In or Register to comment.