Showing posts with label Mail. Show all posts
Showing posts with label Mail. Show all posts

Thursday, February 16, 2017

How to force outlook download all items from exchange server after I clear all the offline emails.

I try to clear the cache to see if i can get all the emails shown in my outlook.

i right click on my inbox folder to get this popup window





then click on the clear offline itmes, then all my emails are gone from my outlook window.

I try to use update Folder button from the SEND/RECEIVE menu




but the Inbox did not load any items from exchange server.

after consult with the network administration, here is the solution

1. go the folder that store the outlook data file

C:\Users\YourUserName\AppData\Local\Microsoft\Outlook

2. rename the Outlook Data File to other name, then close the outlook and skype for business.

3. re-launch the outlook application, boom the outlook will rebuilt the outlook data file and download all the emails items from the exchange server.
















Monday, April 20, 2015

How to use asp.net user control to design a dynamic data loading message template for email Body in asp.net?

if you want to send an email confirmation to the submission, with those user input data being sent and saved in the database.  it is a good approach to use the asp.net custom user control to layout the design of the message template according the user requirement.

we will create a custom asp.net user control naming it as MCustomUC. it will be shown as MCustomUC.ascx in your project file.

In the code behind, define a public property such the uniqure record ID, that we can pass from the host page to the user control, here is the snippet of code from the user control code behind.

 public string UniqueConfirmedID
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        public void LoadData()
        {
            VehicleProvider vehicleProvider = new VehicleProvider();
            List<DealerVehicle> myList = vehicleProvider.GetProgramDetailsByID(ConvertToInteger(UniqueConfirmedID));
            if (myList != null && myList .Count > 0)
            {
                BindControls(myList [0]);
             }
        }

in the submission page, we can dynamically load the user control after the confirmation id is generated

 private string LoadEmailContent(string myID)
        {
            StringBuilder sb = new StringBuilder();
            MCustomUC myCustomUC = (MCustomUC)LoadControl("~/UserControls/MCustomUC .ascx");
            myCustomUC .ID = "emailContentDetail";
            myCustomUC .UniqueConfirmedID= myID;
            myCustomUC .LoadData();
           
            // Render the control into the stringbuilder
            StringWriter sw = new StringWriter(sb);
            Html32TextWriter htw = new Html32TextWriter(sw);
            myCustomUC .RenderControl(htw);
            string body = sb.ToString();
            return body;
        }

then we can call the above method and assign the output string to the email body property of the .net mail object. the user will receive the desired email message with the predefined template.



Tuesday, August 19, 2014

Security Issue with using GMail SMTP to send email in MVC Application

I create a demo app to show the email confirmation in MVC today. Since i do not want to use the company mail server for demo.. then i create a test account in the gmail for this demo app.

I had use email account for test before, I did not encounter any issue. unfortunately i kept getting various error today. here is one of authentication issue.
 

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Source Error:


Line 107:                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
Line 108:
Line 109:                smtp.Send(myMessage);
Line 110:
Line 111:            }

Source File: C:\Users\Dan\Documents\Visual Studio 14\Projects\SecureEmailApp\SecureEmailApp\App_Start\IdentityConfig.cs    Line: 109 




the root cause of the issue is Gmail change the security setting to beef up the security. by default Access for Less secure Apps had been disabled. after i turned Access for less secure apps on. my demo goes very smooth. 


 

after you log into your gmail account and click on the link below to change the security setting for google account.

 https://www.google.com/settings/security/lesssecureapps


This snippet of code now works smoothly

var myMessage = new System.Net.Mail.MailMessage();
            myMessage.To.Add(message.Destination);
            myMessage.From = new System.Net.Mail.MailAddress(
                                "Joe@contoso.com", "Joe S.");
            myMessage.Subject = message.Subject;
            myMessage.Body = message.Body;
            myMessage.BodyEncoding = System.Text.Encoding.UTF8;


            using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient())
            {
                smtp.Host = "smtp.gmail.com";

                smtp.EnableSsl = true;

                NetworkCredential NetworkCred = new NetworkCredential("Mywebtest@gmail.com", "MyPassword1234");

                smtp.UseDefaultCredentials = false;

                smtp.Credentials = NetworkCred;

                smtp.Port = 587;

                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

                smtp.Send(myMessage);

            }