Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...,

I want to send a mail..So while sending ,I need a progress bar or processing Image(or status) and after sending mail ,it should disappear...Can you help me..plz...
Here is the code for mail sending...
C#
public string SendMail(string emailId, string UserName)
{
    string status = string.Empty;
    DataSet dsLoginCredentials = new DataSet();
    try
    {       
        MailAddress SendFrom = new MailAddress("....", "....");
        // to mailid from argument emailId
        MailAddress SendTo = new MailAddress(emailId);
        MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
        MyMessage.Subject = "Login Credentials";
        MyMessage.Body = "Dear " + UserName + " your user name for login :" + emailId + "\n" + " and Password : " + UserName;
        SmtpClient emailClient = new SmtpClient("smtp.gmail.com");
        emailClient.Port = 25;
        emailClient.Credentials = new NetworkCredential("...", "....");
        emailClient.EnableSsl = true;
        emailClient.Send(MyMessage);    
    }
    catch (Exception ex)
    {
        status = "Mail Sending Failed";
    }
    return status;
}

[Edit:Added pre tags]
Posted
Updated 21-Oct-12 20:06pm
v2

Hi Aravind,
The code block you pasted are Server Side. You cannot show a status as you wanted using Postback. Change you code base to use AJAX and use JavaScript for showing the statuses.

All the best.
 
Share this answer
 
Comments
aravindnass 22-Oct-12 2:30am    
can I Get An example for this...?
Hi Arvind,
You can use ajax updatepanel and updateprogress controls to get processing status. Suppose you have a button to send email then you need to put that button into updatepanel and set updateprogress's updatepanelId. In this case whenever you will click on that button processing image will be displayed till the processing is occurring.

Thanks
 
Share this answer
 
Comments
aravindnass 22-Oct-12 2:29am    
Sir..,Can I Get an example...or suggest a link..containing ajax updatepanel and updateprogress...
Satyendra Kumar(Analyst Programmer) 22-Oct-12 7:21am    
<asp:UpdatePanel ID="updatePnl" runat="server" UpdateMode="Conditional">
<contenttemplate>
<asp:Button ID="btnSendEmail" runat="server" onclick="btnSendEmail_Click"/>

<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSendEmail" EventName="Click" />
</Triggers>

<asp:UpdateProgress ID="progress1" runat="server" AssociatedUpdatePanelID="updatePnl">
<ProgressTemplate>
<div style="z-index: 100; position: absolute; margin-top: -200px; margin-left: 30%;">
<img src="../images/ajax-loader1.gif" />
</div>
</ProgressTemplate>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900