ASP.NET - smtp mail setting in web config

Asked By Reena Jain
18-Nov-09 02:08 AM
I was using this mail setting in web.config file
   <appSettings>
        
        <add key="MailServer" value="mail.expertx.us"/>
        <add key="Mailpassword" value="exp223inf"/>
        <add key="MailuserName" value="info@expertx.us"/>
        <add key="Mailhost" value="mail.expertx.us"/>
        <add key="MailPort" value="25"/>
        <add key="ToEmailId" value="rajmera@gmail.com"/>
        <add key="FromEmailId" value="rajmera@gmail.com"/>
        <add key="Bcc" value="rajmera@gmail.com"/>
        
    </appSettings>

 but since client is using godaddy hosting and they giving the below smtp settings for web.config file:

<system.net>
<mailSettings>
<smtp from="username@domain.com">
<network
host="smtpout.secureserver.net"
port="25"
userName="username@domain.com"
password="yourpassword" />
</smtp>
</mailSettings>
</system.net>


also given one note what is for:-Please note that SMTP Authentication sould be basic (anonymous will not work).

Now how should I change the setting in web.config file to add ‘key’ because I’m using following coding in .cs page for sending mails

public bool SendMail(string MailFrom, string MailTo, string Subject, string Message, string AttachedFile, string strCC, string strBcc)
        {
            try
            {
                //Get NetworkCredential UserName and Password for sending mail

                string userName = ConfigurationManager.AppSettings["MailuserName"].ToString();
                string password = ConfigurationManager.AppSettings["Mailpassword"].ToString();
                string smtpHost = ConfigurationManager.AppSettings["MailServer"].ToString();
                int smtpPort = Convert.ToInt32(ConfigurationManager.AppSettings["MailPort"].ToString());

                SmtpClient oSmtpClient = new SmtpClient();
                MailMessage oMailMessage = new MailMessage();
                MailAddress oMailAddress = new MailAddress(MailTo);
                MailAddress fromMailAddress = new MailAddress(MailFrom);
                oMailMessage.To.Add(oMailAddress);
                oMailMessage.From = fromMailAddress;
                
                if (strBcc != "")
                {
                    MailAddress mBcc = new MailAddress(strBcc);

                    oMailMessage.Bcc.Add(mBcc);
                }
                if (strCC != "")
                {
                    MailAddress mCc = new MailAddress(strCC);
                    oMailMessage.CC.Add(mCc);
                }
                oMailMessage.Subject = Subject.Replace("\r\n", "");
                oMailMessage.IsBodyHtml = true;
               
                oMailMessage.Body = Message;
                oSmtpClient.Host = smtpHost;
                oSmtpClient.Port = smtpPort;
                if (!(string.IsNullOrEmpty(AttachedFile)))
                {                    
                     Attachment objAttachment = new Attachment(AttachedFile);
                     oMailMessage.Attachments.Add(objAttachment);
                }
                System.Net.NetworkCredential oNetworkCredential = new System.Net.NetworkCredential(userName, password);
                oSmtpClient.UseDefaultCredentials = false;
                oSmtpClient.Credentials = oNetworkCredential;
                oSmtpClient.Send(oMailMessage);
               return true;
            }
            catch (Exception ex) { }
            {

            }
            return true;
        }

So how should I adjust the new smpt setting with above code

Thanks in advance

smtp mail setting in web config  smtp mail setting in web config

30-Nov-09 09:09 PM
Adapt this snippet -

Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
        MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
        Response.Write("host: " + settings.Smtp.Network.Host + "<br />");
        Response.Write("port: " + settings.Smtp.Network.Port + "<br />");
        Response.Write("Username: " + settings.Smtp.Network.UserName + "<br />");
        Response.Write("Password: " + settings.Smtp.Network.Password + "<br />");
        Response.Write("from: " + settings.Smtp.From + "<br />");

For more details, refer to this - http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/09/06/accessing-web-config-file-smtp-mail-settings-programmatically.aspx

thanks, i will try it and i think it will work for me  thanks, i will try it and i think it will work for me

01-Dec-09 01:12 AM
end of post
Create New Account
help
authentication modes and its implementation in projects hi, i am doing a project in asp.net. . i want to use a authentication mode in this project.it is a educational based, regarding some simple c, c++ programs find the details of persons who visits my site.so i want to do some authentication in this project. How To: Use Forms Authentication with SQL Server in ASP.NET 2.0 patterns & practices Developer Center J.D. Meier 0 • SQL Server 2000 Summary This How To shows you how you can use forms authentication with the SQL Server membership provider. Forms authentication with SQL Server is most applicable in situations where users of your application are not login page using the new membership Login control, configure your Web application to use forms authentication, create the user store database, grant database access to your Web application account, configure ASP a Web Application with a Login Page Step 2. Configure the Web Application for Forms Authentication Step 3. Configure ASP.NET for Membership Step 4. Test the Forms Authentication Deployment Considerations
Z. Thanks in Advance. HOWTO: Configuring a Office SharePoint Server 2007 Publishing Site with Dual Authentication Providers and Anonymous Access This article was been updated for WSS v3 / MOSS 2007 RTM public realm of the Internet. Therefore, many companies prefer to implement some type of forms authentication where users login using a username or email address and password to gain access to access and utilize everything that ASP.NET 2.0 has to offer… including the pluggable authentication model. It is this pluggable authentication that I will leverage to provide multiple authentication options for a single Web site. In this article I want to demonstrate how to each Web application, or IIS Web site, will be configured for a specific type of authentication mechanism (Windows Authentication [AD] and Forms Authentication). Then I'll configure both Web applications so they can access the users and roles
what is different between authentication and authorization? different between authentication and authorizationplease give me some details with example. thansk advanc Authentication:-> Authentication is a process of identifying a user based on their credentials(means user id and of determining whether an authenticated user is allowed to access a specific resource or not. Authentication and authorization are two tightly-coupled concepts to form the core of security for .NET applications. Authentication is the process of determining and verifying the identity of users based on the users on to a system, he / she will be authenticated first before he / she is authorized. Authentication There are three types of authentication in ASP .NET: 1. Form authentication 2. Windows authentication 3. Passport authentication Form Authentication You
smtp mail setting in web config I was using this mail setting in web.config file gmail.com " / > < / appSettings > but since client is using godaddy hosting and they giving the below smtp settings for web.config file: <system.net> <mailSettings> <smtp from = "username@domain.com"> <network host = "smtpout.secureserver.net" port = "25" userName = "username@domain.com" password = "yourpassword" / > < / smtp> < / mailSettings> < / system.net> and also given the following instruction:-Please note that SMTP Authentication should be basic (anonymous will not work). so whats the meaning of it. Now how n" , "" ); oMailMessage.IsBodyHtml = true ; oMailMessage.Body = Message; oSmtpClient.Host = smtpHost; oSmtpClient.Port = smtpPort; if (!( string .IsNullOrEmpty(AttachedFile))) { Attachment objAttachment = new Attachment (AttachedFile); oMailMessage.Attachments.Add(objAttachment); } System.Net. NetworkCredential oNetworkCredential = new web.config:: <configuration> <!- - Add the email settings to the <system.net> element - -> <system.net> <mailSettings> <smtp> <network host = " relayServerHostname " port = " portNumber " userName = " username " password = " password " / > < / smtp> < / mailSettings> < / system.net> <system.web