Wrox Programmer Forums
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2004, 01:47 AM
Authorized User
 
Join Date: Dec 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to kvanchi
Default mail popup

hi
i have created a form in which the end user will post some request
as soon as the end user post a request
i should be informed of that through the corporate mail account
we are using MS oulook for this
so my question is
how to do pop up mail as soon as the end user post a request
can any body help me in this
thank u
my mail is [email protected]

 
Old December 16th, 2004, 07:50 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default

I'm going to be putting in alot of code for a really simple process. Generally I create a separate class that handles emails for my code...Actually this was created for my organization from a MS consultant. Then I can call any function in this class and I put in an example. I also use an AppSetting in the web.config, and I included that line at the bottom.

//----------------------Mail Class----------------------------------------
    /// <summary>
    /// This class is used to send emails (via CDONTS) from within the CMS system. The system requires a
    /// valid SMTP server, and this address is controlled through the web.config AppSetting "MailServer".
    /// </summary>
    /// <remarks>Author: Simon Chester (Microsoft) March 2003</remarks>
    public class MailHandler
    {
        private ErrorHandler _err;
        private MyCompanyDirectory _hrDir;
        private string _mailServer;
        const string ERROR_PAGE_URL = "/MyCompany/ErrorPages/MailError.aspx";

        /// <remarks>Access Type: Public</remarks>
        /// <summary>
        /// This is the constructor for the MailHandler class.
        /// </summary>
        public MailHandler()
        {
            _err = new ErrorHandler();
            _hrDir = new MyCompanyDirectory();
            _mailServer = ConfigurationSettings.AppSettings["MailServer"];
        }

        /// <remarks>Access Type: Public</remarks>
        /// <summary>
        /// This function is used to trigger an email to the author of a posting
        /// when the editor declines it. The function is called from the Declined
        /// event in the global.asax.
        /// </summary>
        /// <param name="thisPosting">(Microsoft.ContentManagement.Pu blishing.Posting) The posting object which has been declined.</param>
        /// <param name="serverName">(string) The name of the server on whihch the posting
        /// resides.</param>
        /// <param name="response">(System.Web.HttpResponse) The HttpResponse Object. Used to redirect the user
        /// if an error occurs.</param>
        /// <param name="editorName">(string) The full name of the editor. This should be in
        /// the form of: WinNT://DomainName/UserName.</param>
        public void SendDeclineEmail(Posting thisPosting, string serverName, System.Web.HttpResponse response, string editorName)
        {
            string author;
            string editor;
            string subject;
            string body;

            //get the authors email address from the AD system via GetEmailAddress
            author = GetEmailAddress(thisPosting.LastModifiedBy.ClientA ccountName);
            //if an address is found continue
            if(author!=null)
            {
                //get the editors email address
                editor = GetEmailAddress(editorName);
                //if an address is found, continue
                if(editor!=null)
                {
                    //construct the subject and body of the mail address, including a
                    //link to the posting
                    subject = "Declined: A posting was declined in the "+ thisPosting.Parent.DisplayName + " channel.";
                    body = "The following item was declined:<br><br>";
                    body+= "<a href='http://" + serverName + thisPosting.UrlModeUnpublished + "&wbc_purpose=Basic'>"+ thisPosting.DisplayName +"</a>";
                    //Send the email
                    SendMail(author, editor, "", subject, body);
                }
                //if an editor email could not be found, present the error to the user
                else
                {
                    DisplayError(serverName, thisPosting, response);
                }
            }
            //if an author email could not be found, present the error to the user
            else
            {
                DisplayError(serverName, thisPosting, response);
            }
        }

        /// <remarks>Access Type: Private</remarks>
        /// <summary>
        /// This function redirects the user to an error page to inform them that the email was
        /// not sent and to display the reason. A link is also provided to continue.
        /// </summary>
        /// <param name="serverName">(string) This is the name of the server which was processing the request.</param>
        /// <param name="thisPosting">(Microsoft.ContentManagement.Pu blishing.Posting) The posting object of the page that was being processed.</param>
        /// <param name="response">(System.Web.HttpResponse) The HttpResponse object. This is used to redirct the user
        /// to an error page.</param>
        private void DisplayError(string serverName, Posting thisPosting, System.Web.HttpResponse response)
        {
            string nextUrl = "http://" + serverName + thisPosting.UrlModeUnpublished;
            string errorMessage = "The email to " + thisPosting.LastModifiedBy.ClientAccountName + " was not sent. The error has been logged on the server.<br>Error Message:<br>" + _hrDir.LastKnownError;
            response.Redirect(ERROR_PAGE_URL + "?nexturl=" + nextUrl + "&error=" + errorMessage);
        }

        /// <remarks>Access Type: Private</remarks>
        /// <summary>
        /// This function calls out to the MyCompanyDirectory class to grab the email address
        /// for the person passed in. If the email address cannot be found, the function will
        /// log the error in the system log.
        /// </summary>
        /// <param name="username">(string) The full username for the person the address must be found for.
        /// This should be in the form of; WinNT://DomainName/UserName</param>
        /// <returns>(string) Valid elmail address in the form of; [email protected]</returns>
        public string GetEmailAddress(string username)
        {

            string emailAddress;
            emailAddress = _hrDir.GetEmailBySAM(username);
            if(emailAddress==null)
            {
            // return _hrDir.LastKnownError;
                _err.LogError(_hrDir.LastKnownError, "MailHandler.GetEmailAddress", EventLogEntryType.Error, true);
                emailAddress = null;
            }
            return emailAddress;
        }

        /// <remarks>Access Type: Public</remarks>
        /// <summary>
        /// This function is used to actually trigger the email. The function uses
        /// System.Web.Mail to fire the message, which currently wraps around
        /// CDONTS. The System requires a valid SMTP server, the name of which is held
        /// in the AppSettings section of web.config, under the "MailServer" key.
        /// </summary>
        /// <param name="to">(string) Email recipient. Can be multiple people seperated by a semi-colon</param>
        /// <param name="from">(string) Email sender</param>
        /// <param name="subject">(string) Subject line for the email.</param>
        /// <param name="body">(string) Main body of the email.</param>
        /// <returns>(string) Error message if the mail fails to send.</returns>
        public string SendMail( string to, string from, string cc, string subject, string body)
        {
            string error = "";
            try
            {
                MailMessage newMail = new MailMessage();
                newMail.To = to;
                newMail.From = from;
                newMail.Cc = cc;
                newMail.Subject = subject;
                newMail.Body = body;
                newMail.BodyEncoding = System.Text.Encoding.ASCII;
                newMail.BodyFormat = MailFormat.Html;
                string str = SmtpMail.SmtpServer;
                SmtpMail.SmtpServer= _mailServer;
                SmtpMail.Send(newMail);
            }
            catch(Exception ex)
            {
                error = ex.Message;
                //throw ex;
            }
            return error;
        }
    }

//---------------------Call to function in Mail Class --------------------
//send email to user confirming username & pwd

string sTo = useremail;
string sFrom = "[email protected]";
string sSubj = userdesc + " Request for Application Permissions";
string sCC = "[email protected]";

//build email body
StringBuilder _sb = new StringBuilder();
_sb.Append("Dear MyCompany User:");
_sb.Append("<p>Your user account has been activated or modified.");
_sb.Append("<p>Please use the following username and password to login to <a href=http://MyCompany.MyCompany.com/>MyCompany</a>: ");
_sb.Append("<p>Username: " + userlogin);
_sb.Append("<p>Password: " + _random);
_sb.Append("<p><b>After you login, please change your password by selecting Applications, Change My Password. Also, please review the <a href=http://MyCompany.MyCompany.com/departments/legal/legalinfo/site_usage_info_agreement.htm>Site Usage & Information Agreement</a>.</b>");
_sb.Append("<p>We hope you will find the following links useful:</p>");
_sb.Append("<p><a href='http://MyCompany.MyCompany.com/Resources/Help/UserTools/login_help.htm'>Login Help</a></p>");
_sb.Append("<p><a href='http://MyCompany.MyCompany.com/Resources/Help/UserTools/forgot_password.htm'>Forgot Password?</a></p>");
_sb.Append("<p><a href='http://MyCompany.MyCompany.com/Resources/Help/FAQs/'>Frequently Asked Questions</a></p>");
_sb.Append("<p><a href='http://MyCompany.MyCompany.com/Resources/Help/UserTools/edit_your_user_profile.htm'>Edit User Profile</a> (to add or remove applications)</p>");
_sb.Append("<p>If you need additional assistance, simply reply to this email or call 1-xxx-xxx-xxx.</p>");
_sb.Append("<p>Regards,</p>");
_sb.Append("<p>MyCompany Security Administrator</p>");

MailHandler mh = new MailHandler();

mh.SendMail(sTo,sFrom,sCC,sSubj,_sb.ToString());

//---------------------line to include in config file --------------------

<add key="MailServer" value="smtpmail.MyCompany.com" />






Similar Threads
Thread Thread Starter Forum Replies Last Post
Send mail and attachments with PHP mail function Lofa Beginning PHP 1 June 2nd, 2008 03:24 PM
problems sending mail with java mail gandacuboy J2EE 2 December 20th, 2006 03:05 PM
Sending e-mail to different mail box! Calibus Classic ASP Databases 4 September 3rd, 2004 05:48 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.