Results 1 to 8 of 8

Thread: how to enable SMTP Authentication with System.Web.Mail classes?

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Resolved how to enable SMTP Authentication with System.Web.Mail classes?

    I have written the code to send email using Mail classes in System.Web.Mail namespace but my smtp server needs to "enable SMTP Authentication" setting.

    How can I do this?
    Last edited by ZeBula8; Feb 26th, 2005 at 10:24 PM.

  2. #2
    Addicted Member
    Join Date
    Sep 2004
    Posts
    133

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    I believe this is what you are looking for:
    VB Code:
    1. Dim message As New MailMessage
    2.  
    3.         message.To = "[email protected]"
    4.  
    5.         message.From = "[email protected]"
    6.         message.Subject = "Subject
    7.         message.BodyFormat = MailFormat.Html
    8.  
    9.         message.Body = "Body"
    10.  
    11.         message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp Server Address")
    12.         message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25)
    13.         message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2) '2 to send using SMTP over the network
    14.         message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1) '1 = basic authentication
    15.         message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "SMTP User Name")
    16.         message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "PASSWORD")
    17.  
    18.         Try
    19.             SmtpMail.Send(message)
    20.         Catch ex As Exception
    21.  
    22.         End Try

  3. #3

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    unfortunately, those pages/links are no longer available -

    I converted this code to C#, which is what I'm using, but still no luck...

    I can send the mail just fine from my old smtp server but this new one requires smtp authentication which has put a real dent in my app...

    thanks for your help, though; I spent the night researching all over MSDN and learned a few new things - so all was not wasted


    I did manage to find this bit of information and a component that is supposed to do what I'd like - yet to have bought it and tried though...
    SMTP Authentication component for sending email with ASP.NET
    Last edited by ZeBula8; Feb 24th, 2005 at 01:02 PM.

  4. #4
    Addicted Member
    Join Date
    Sep 2004
    Posts
    133

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    My SMTP server also require authentication for sending an email. In the message.fileds part I have to specify my server and account information and it works. Do not atttempt to go to the addresses listed below they are merely schema namespaces.

    VB Code:
    1. ' Change SMTP Server Address (Ex: mail.domain.com)
    2. message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "SMTP Server Address")
    3. message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25)
    4. message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2) '2 to send using SMTP over the network
    5. message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1) '1 = basic authentication
    6. ' User information (EX: [email][email protected][/email])
    7. message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "SMTP User Name")
    8. ' User Password (EX: password)
    9. message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "PASSWORD")

    It is free and it works.

    My question to you is does your SMTP server run on the default port (25), and use basic authentication.

    Other sources of information:
    http://www.codeproject.com/dotnet/SM...entication.asp
    http://blogs.wwwcoder.com/pradeepd/a...01/28/236.aspx
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration.aspp/url]
    http://www.eggheadcafe.com/PrintSear...asp?LINKID=622
    Last edited by schenz; Feb 24th, 2005 at 09:01 PM.

  5. #5

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    yes, smtp server runs port 25 and uses basic authentication - but here is the error I am getting:

    Code:
    The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Runtime.InteropServices.COMException: The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available 
    
    Source Error: 
    
    
    Line 177:			try 
    Line 178:			{
    Line 179:				SmtpMail.Send(message);
    Line 180:			}
    Line 181:			finally{}
     
    
    Source File: c:\inetpub\wwwroot\rosary\registration.aspx.cs    Line: 179 
    
    Stack Trace: 
    
    
    [COMException (0x80040211): The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
    ]
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
       System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
       System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) +29
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args)
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
    
    [HttpException (0x80004005): Could not access 'CDO.Message' object.]
       System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
       System.Web.Mail.CdoSysHelper.Send(MailMessage message)
       System.Web.Mail.SmtpMail.Send(MailMessage message)
       Rosary.registration.Button2_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\rosary\registration.aspx.cs:179
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain()
    Here is the code i am using:

    Code:
    			MailMessage message = new MailMessage();
    
    			message.To = "[email protected]";
    
    			message.From = "[email protected]";
    			message.Subject = "Testing Internet SmtpMail";
    			message.BodyFormat = MailFormat.Html;
    
    			message.Body = "body";
    
    			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.thecrystalrosary.com");
    			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
    			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2); //2 to send using SMTP over the network
    			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); //1 = basic authentication
    			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
    			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
    
    			try 
    			{
    				SmtpMail.Send(message);
    			}
    			catch (Exception e) 
    			{
    				// trap here
    			}

  6. #6
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    I have an email server that requires authentication and I turned around and added to the email server the ip address of the webserver so that authentication is not required from this IP address.

    Can you do the same with your email server? this would save a lot of headache. I started down the path your on and then just opened up my email server only that that one IP address as a trusted host.

    Jerel

  7. #7
    Addicted Member
    Join Date
    Sep 2004
    Posts
    133

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    I do agree that Phenglai's solution is one of the easiest ways to solve this problem (unless it's another problem). I did not have that option and the code works fine for me.

    I googled the error code and came up with some other possibilities (hence my other problems statement)

    This may be happening if you are using some sort of proxy configuration on the box sending the emails, or you have some security software blocking port 25 on the box sending the emails. I came up with this from:
    http://www.systemwebmail.com/faq/4.2.9.aspx
    http://victor.carotena.net/weblog/archives/000016.php

    You may want to investigate this (especially if you can allow the problem box to be allowed to relay and you continue having the problem)

  8. #8

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: how to enable SMTP Authentication with System.Web.Mail classes?

    I've still been plagued with this problem from this particular smtp server - I have another server that doens't give a bit of a tiff -

    in any case, I've discovered a great assembly that pretty much does everything and anything you would want it to do -if you have .NET framework of 1.1 (below that, authentication won't work)... and I'm not a spokesperson for the group, either -

    ASP.NET Email for SMTP has a nice little component- you can check out the evaluation version, fully functional, too - before you decide if it's worth your application's time and money -

    I've checked it out and was quite impressed with it's features, not to mention it's extensive help file - amazing!!

    anyway, for the meantime, I will use my other smtp mail server until my resolves with this other smtp are sorted out...

    I'd like to thank you for all of your help and time spent in dealing with this -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width