This project is read-only.

SMTP - Auth (Modification)

Topics: Developer Forum
Dec 22, 2006 at 12:23 PM
Hallo,

I really like your Starterkit and I think it has a big potential to become the most wanted starterkit.

The only thing that really su** is that the most provider required SMTP-Auth to send an email.
I've tried three providers and all required SMTP-Auth.

So i decided to modify your Starterkit. (by the way, you've done a great coder job. It's really easy to understand how the things work together.)

I hope you will integrate my code in the next version so that other users can use that feature too. Below see the list of changes I've made. All is well commented. If you wish I can send you an Zipfile with the codefiles.

Changes made:

1. Website.aspx

Added three textfields: txtSmtpUser, txtSmtpPassword, txtSmtpDomain

1.1 Website.aspx.cs

in the btnSave_Click event:
_website.SmtpUser = txtSmtpUser.Text.Trim();
_website.SmtpPassword = txtSmtpPassword.Text.Trim();
_website.SmtpDomain = txtSmtpDomain.Text.Trim();

in the Page_Load event:
txtSmtpUser.Text = _website.SmtpUser;
txtSmtpPassword.Text = _website.SmtpPassword;
txtSmtpDomain.Text = _website.SmtpDomain;

2. website.cs

Added three Public Properties: SmtpUser, SmtpPassword, SmtpDomain

Added three public strings in WebSiteData class: SmtpUser, SmtpPassword, SmtpDomain

3. StringsRes.resx

Added three Ressource Entrys: admWebsiteSmtpUser, admWebsiteSmtpPassword, admWebsiteSmtpDomain

4. StringsRes.de.resx (Have to be done for the other Languages too)

Added three Ressource Entrys: admWebsiteSmtpUser, admWebsiteSmtpPassword, admWebsiteSmtpDomain

5. Contactform.ascx.cs

Added an if statement.

The statement in the btnSubmit_Click event (to check if SMTP-Auth have to be used)

if (_website.SmtpUser != "" && _website.SmtpPassword != "" && _website.SmtpDomain != "") {
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(_website.SmtpUser, _website.SmtpPassword, _website.SmtpDomain);
}

kind Regards
ripi1000
Jan 2, 2007 at 6:49 AM
I'm wondering that no one is interested in the modifikation. Have every provider in other states than germany open relay mailservers???

I can't belive that. So how do other solve that problem??

It would be very nice if some one can explain it to me, how it works without SMTP-AUTH.

greetz
ripi1000
Jan 3, 2007 at 1:54 AM
There is a ways to specify SMTP-auth data for your application. Edit your web.config and paste:

<system.net>
<mailSettings>
<smtp from="test@foo.com">
<network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>

Update values according to your needs. I didn't check if MWPSK is compatible with this as it defines an SMTP server internally but IMO the whole SMTP server section as parameters for portal could be removed and documentation could simply mention this solution as standard way to define your SMTP server.

Anyway, could be a starting point for your modifications.

Hope this helps ;-)
Jan 3, 2007 at 2:03 PM
Hello ripi1000 and TBPrince

thanks for your contribution! I will open a new issue for SMTP Authentication, and probably the next release will contain the fix.

The problem should only occur, when the declared mail server enables authentication (in order to reduce abuse).

thanks and best regards,
pascal
Jan 3, 2007 at 2:48 PM
Hello webeasy,

thank you for looking into this. He is right to state that many providers require authentication in order to send e-mails out (and some of them also require non-standard port).

Declarative syntax used in web.config is very easy to setup, IMO, and thus main system could avoid defining such parameters internally (right now, it only supports SMTP-server address).

However, a solution by code or web.config modifications will surely be welcomed.

Thank you for your support.
Jan 4, 2007 at 1:00 PM
Hello,

nice to hear that the problem will be solved in future versions.

I think the integration into the configuration site is more user friendly than making entrys in the web.config. (just my 2 cent :-))

Greetz
ripi100
Mar 12, 2008 at 1:57 PM
For my provider, I had to modify the sectioncontrols\contactform.ascx.cs smtp networkcredentials line. It seems that by sending the smtpDomain parameter with the credentials invoked a 'user not found' error when sent to someone outside the smtpdomain.

The change (along with the commented out code) is follows. Perhaps someone else can figure out how to make this a more automatic set-up choice issue, rather than having to slog through discussion groups, 'help' topics and other sources before figuring it out.

around line 95 or so in the code make it look like this:

// client.Credentials = new NetworkCredential(_website.SmtpUser, _website.SmtpPassword, _website.SmtpDomain);
client.Credentials = new NetworkCredential(_website.SmtpUser, _website.SmtpPassword);

Another "problem" with this is that the contact form isn't protected by a captcha, nor does it require membership to use. So this form could be used by nefarious folks for spam -- thereby exposing your email account to blacklisting (which would make it pretty useless). Could someone tackle that issue as well?

Brad
Nov 29, 2008 at 7:13 PM
Edited Nov 29, 2008 at 7:15 PM
Thank you very much for this fix TBPrince, so easy too.

There is a way to specify SMTP-auth data for your application. Edit your web.config and paste:

<system.net>
<mailSettings>
<smtp from="test@foo.com">
<network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
Jan 18, 2009 at 12:05 AM
Edited Jan 18, 2009 at 12:06 AM
Hi,

I have the same problem, but I can't get it working.
I have changed the web.config like mentioned above, but maybe on the wrong line ?
When I try to use the contact form, I still get the error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 User not authenticated "

Can someone help me?

Roy
Jan 27, 2009 at 11:03 PM
I created Issue http://www.codeplex.com/MyWebPagesStarterKit/WorkItem/View.aspx?WorkItemId=20850 - sorry I missed this thread
Artur
Feb 25, 2011 at 6:01 PM
Edited Feb 25, 2011 at 6:02 PM

I created a new section control to allow secure connections to SMTP, specifically to support implicit SSL. The code is tested on MWPSK 1.2.1 and based on the original Contact Form source. It adds a new section called Secure Contact Form and uses the statndard config for all the variables. The only thing that is hard coded is the port which can be modified in the source file. You can download it from here:

http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=mywebpagesstarterkit&DownloadId=211508

*** Note that this uses the deprecated System.Web.Mail namespace as currently System.Net.Mail does not support implicit secure (SSL) SMTP connection.

I commented the code well so you should be able to make any necessary modifications without issue. Following are the instructions to install:

The patch includes two files, SecureContactForm.ascx and SecureContactForm.ascx.cs to upload to the SectionControls directory, a modified StringsRes.resx file to upload to App_GlobalResources and SecureContactForm.cs to upload to App_Code\Sections.