Problems sending emails

Posted on 2005-04-26
Last Modified: 2010-08-05
Hi.  I'm getting this error:

Stack Trace:
System.Web.HttpException: Could not access 'CDO.Message' object. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80040211): The message
could not be sent to the SMTP server. The transport error code was
0x800ccc67. The server response was 421 Sorry, you must log in before
using this server. --- End of inner exception stack trace --- at
System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters) at
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, ParameterModifier[]
modifiers, CultureInfo culture, String[]
namedParameters) at
obj, String methodName, Object[] args) --- End of inner exception stack
trace --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
obj, String methodName, Object[] args) at
System.Web.Mail.CdoSysHelper.Send(MailMessage message) at
System.Web.Mail.SmtpMail.Send(MailMessage message) at
RobertsDB.RobertsDB.SendMail(String reason, Int32 order_id) at
Roberts.NewOrder.Submit1_ServerClick(Object sender, EventArgs e) at
System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) at
er.RaisePostBackEvent(String eventArgument) at
sourceControl, String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at

This is the source code in a nutshhell:

                  string mailto = "xxxxx";
                  string mailcc = "XXXXX";
                  string mailbcc = "";
                  string mailfrom = "XXXXXXX";
                  string mailsubject = "BLAH BLAH BLAH";
                  string mailbody = "<Br>";
                  SmtpMail.SmtpServer = "SMTP.mailservice.COM";
                  MailMessage mail = new MailMessage();
                  mail.Priority = MailPriority.High;  
                  mail.BodyFormat = MailFormat.Html;
                  mail.To = mailto;
                  mail.Cc = mailcc;
                  mail.Bcc = mailbcc;
                  mail.From = mailfrom;
                  mail.Subject = mailsubject;
                  mail.Body = mailbody;

***    The wierd thing is that this works on some occasions, doesn't work other times.   I'm not sure why.   Is there a different way to send the email that I should be doing?   Is there server timing out?    Is there a timeout property I can submit to make it wait longer before timing out?    
Question by:keith_dude
    LVL 22

    Expert Comment


    The issue is you are trying to use a SMTP server which need to be authenticated nefore using it..

    You need to add your userid and the password for an email account of that smtp server to enable sending an email from this server

    for more details on it.. u can ask your mail server administrator..

    LVL 1

    Author Comment

    Ok.    I've got a username/password.  How do I add it?
    LVL 22

    Accepted Solution


    add these lines

    mail.Fields.Add("", cdoBasic);
    mail.Fields.Add("", userName);
    mail.Fields.Add("", pw);

    where username and pw is your username and password for email acocunt..

    LVL 1

    Author Comment

    What is cdoBasic?   I'm getting an error on that line that it doesn't recognize it.   Is it a value, like 1, 2, 3?  
    LVL 10

    Assisted Solution

    Const cdoBasic = 1
    LVL 1

    Author Comment

    No dice.     You do realize this is a c#/.net question...right?  

    Is there a better way to send emails?

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now