• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 744
  • Last Modified:

Problems sending emails

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
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
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
System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventH
andl
er.RaisePostBackEvent(String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at
System.Web.UI.Page.ProcessRequestMain()



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;
                  SmtpMail.Send(mail);


***    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?    
0
keith_dude
Asked:
keith_dude
  • 3
  • 2
2 Solutions
 
neeraj523Commented:
Hello

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..

neeraj523
0
 
keith_dudeAuthor Commented:
Ok.    I've got a username/password.  How do I add it?
0
 
neeraj523Commented:

add these lines

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pw);

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

neeraj523
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
keith_dudeAuthor Commented:
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?  
0
 
ThaSmartUnoCommented:
<no-points>
Const cdoBasic = 1
</no-points>
0
 
keith_dudeAuthor Commented:
No dice.     You do realize this is a c#/.net question...right?  

Is there a better way to send emails?
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now