Utilizing mailSettings config section?


#1

I have an asp.net 2.0 app which uses membership and already has the smtp mailSettings section in the web.config file. I’d like to be able to use this to get the host info for creating the Aspose SmtpClient object. Has anyone done this? Is there an easy way to read the host info out of that config section and pass it to the Smtp object?



#2

Hi, thanks for considering Aspose.Network.

Our development team is working on this issue. We will provide some solutions ASAP.

Thanks for your patience.


#3

Hi, digitalman,



Thanks for your considering aspose.network.



The issue about using the mailsetting section in the web.config file is
studied carefully by our developers. Because of the feature is
supported only in .net 2.0 and the aspose.network is still based on
.net 1.1, it is a little bit difficult to support that features at
present.



However, we will have some plans to port the aspose.network to pure .net 2.0 and integrate with more features of .net 2.0.



We have created some samples code for you, and feel free to use it
according to your needs. If you have any problems, we are more than
glad to provide any helps or sample codes.



public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

SmtpSection smtpSec =
(SmtpSection)ConfigurationManager.GetSection(“system.net/mailSettings/smtp”);


Response.Write(smtpSec.Network.Host + “\r\n”);

Response.Write(smtpSec.Network.UserName + “\r\n”);

Response.Write(smtpSec.Network.Password + “\r\n”);

Response.Write(smtpSec.Network.Port + “\r\n”);



//initialize the mailmessage class

SmtpConnection conn = new
SmtpConnection(smtpSec.Network.Host, smtpSec.Network.Port,
smtpSec.Password, smtpSec.Password);

//create MailMessages

MailMessage msg = new
MailMessage(smtpSec.From, "yourname@aspose.com", “hello”, “hello
mailSettings”);

msg.SendAsync(conn);

}

}



Web.Config file as following

<?xml version="1.0"?>



<system.net>




<network host="localhost" port="25"

userName=“youraccount” password=“yourpassword”/>





</system.net>



#4

That’s perfect! Exactly what I was looking for. Thanks.