1

I have been roaming forums and not finding any answer to my question. all of the solution (and question) is about using Microsoft.Office.Interop.Outlook; for some reason I am not allowed to use any office.interop.

I even tried:

MailAddress fromAddress = new MailAddress("[email protected]"); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = fromAddress; message.To.Add("[email protected]"); message.CC.Add("[email protected]"); message.Subject = "theSubject"; message.Body = "TheBody"; SmtpClient smtpClient = new SmtpClient("zzz.server.xxx"); smtpClient.Credentials = new NetworkCredential("[email protected]", "password"); smtpClient.Send(message); 

the code fail to authenticate the credential, even after I hard-coded the password, but I feel that there must be a better way.

3
  • 1
    I found this eventually helpful stackoverflow.com/questions/6489397/… Commented Mar 3, 2013 at 4:37
  • @AlinaB. not allowed to use any office.interop Commented Mar 3, 2013 at 4:38
  • Is this winforms, web, WPF or what? Obviously its not VSTO yet you've tagged it Outlook, so what type of application do you need to send emails from? Commented Mar 3, 2013 at 5:04

3 Answers 3

2

There is a lot to be desired of your question. Can you post the response from the server or the error you are receiving?

Here are some observations and feedback that may help you Specify the port

SmtpClient smtpClient = new SmtpClient("zzz.server.xxx", PORTNUMBER); 

Set some of the basic properties

smtpClient.Timeout = 10000; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; //must be set prior to credentials smtpClient.Credentials = new NetworkCredential("username", "pass"); 

Set the message encoding

message.SubjectEncoding = System.Text.Encoding.UTF8; message.BodyEncoding = System.Text.Encoding.UTF8; 

Send Asyncronously and use a callback to determine the result

//add callback smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); //set token string userToken = "tokenString"; //send asynchronously smtpCient.SendAsync(message, userToken); public static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e) { // Get the unique identifier for this asynchronous operation. String token = (string) e.UserState; if (e.Cancelled) { //do something if it was cancelled } if (e.Error != null) { MessageBox.Show( e.Error.ToString()); } else { MessageBox.Show("Message sent."); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Just to add, you may need to Enable SSL using the EnableSsl property on the SmtpClient. SmtpClient Class
0

Have you verified the credentials, including the format of the username through configuring the account in an alternative client, such as Outlook?

You might need:

smtpClient.Credentials = new NetworkCredential("sender", "password"); 

or

smtpClient.Credentials = new NetworkCredential("DOMAIN\sender", "password"); 

Comments

0

Is your email server an Exchange Server? If so, you can use the Exchange Web Services (EWS) to send emails and save copies in the Sent Items folder. A simple example can be seen here:

Send Exchange Email

More Sample Code

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.