My environments are
Server Machine: DocuShare Server 6
Client Machine: Windows XP where DocuShare client 6, DocuShare outlook client 3, MS outlook 2007 and our C# application are installed.
We have a C# application to download mail message from DocuShare server using DocuShare API.
The application successfully downloads docushare mail messages as MSG file. But when the mail message has attachment with long name (in my case the attachment file name is
"New Tzunami Outlook Attachment Extractor User Guide 20100902.docx"), the application throws Windows Socket error while downloading. If the attachment file name is short, mail messages are downloaded successfully.
Here are the codes:
private void btnDownloadMails_Click(object sender, EventArgs e)
{
MailArgument mailArg = new MailArgument();
mailArg.server = textServer.Text;
mailArg.user = textUser.Text;
mailArg.password = textPwd.Text;
DownloadMailAsMsg(mailArg);
}
void DownloadMailAsMsg(object s)
{
MailArgument mailArg = s as MailArgument;
long status = 0;
DSServerMap.Server dsserver = new DSServerMap.Server();
if (!SelectMappedServer(ref dsserver, mailArg.server))
return;
dsserver.DocuShareAddress = mailArg.server;
dsserver.UserName = mailArg.user;
dsserver.Password = mailArg.password;
dsserver.Domain = "DocuShare";
status = dsserver.Logon();
if (status == 0)
{
IItemObj objParentItem;
string[] emailHan = { "MailMessage-2919", "MailMessage-2924", "MailMessage-2925", "MailMessage-2926", "MailMessage-2926", "MailMessage-15", "MailMessage-30", "MailMessage-31" };
foreach (string handnum in emailHan)
{
objParentItem = (IItemObj)dsserver.CreateObject(handnum);
DSGATEWAYLib.IGatewayHandler gateway = (DSGATEWAYLib.IGatewayHandler)dsserver.Open();
objParentItem.AttachGateway(gateway, true);
objParentItem.Name = #"D:\emtest\" + handnum + ".msg";
int flag = objParentItem.DSDownload(0);
}
}
}
Where I stuck is at the line: int flag = objParentItem.DSDownload(0); while downloading email which have attachment file named "New Tzunami Outlook Attachment Extractor User Guide 20100902.docx".
For checking, we trimmed the attachment file name to "ANew Tzunami OutAttachmen 01.docx" but we still got the same error.
The code objParentItem.DSDownload(0) return -300 value and at the same time DocuShare error dialog box pops up with following message
"Winsock error 123"
When DsAxess console is used to download the same mail message, we got the same WinSock error, so nothing can be done;).
We used WorldClient mail application for sending emails. We sent email with the attachment having "ANew Tzunami OutAttachmen 01.docx" file name using WorldCLient, which we failed to download. For the sake of tesing we used another application to send the email with the same attachment. This time we used MS word to send email with the same attachment and we succeeded downloading email using C# app and DsAxess console as well.
If you have anything about this, please share with us.
thank you.
Prakash
Related
I've created an VSTO-Add-In for Outlook, which imports several data from an pdf-file and saves the data as an MS-Excel-File. After successfully process i start a Toastnotification ,which enables an fast opening of this Excel-file by clicking on the notification in the info-center. The problem: clicking on the notification of other incoming e-mails (Outlook) doesn't work anymore. Nothing happens. How can i solve this problem?
public Ribbon1()
{
Initialize();
}
private async Task Initialize()
{
await Task.Run(() =>
{
ToastNotificationManagerCompat.OnActivated += async toastArgs =>
{
ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
await Task.Run(() =>
{
if (!string.IsNullOrEmpty(toastArgs.Argument) && !toastArgs.Argument.Contains("idEPST=ignore") && toastArgs.Argument.Contains("idEPST="))
{
string datei = toastArgs.Argument.ToLower().Replace("idEPST=", String.Empty).Trim().Replace(".xls", "");
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = "excel.exe";
si.Arguments = $"\"C:\\folder\\file.xls\" /{datei}";
Process.Start(si);
}
});
};
});
}
}
//and later
new ToastContentBuilder()
.AddAudio(null, silent: true)
.AddArgument("idEPST", filename)
.AddHeader("identifier", "My Excel App Name", String.Empty)
.AddText($"{name}, {firstname}", hintMaxLines: 1)
.AddText("... sucessfully saved.")
.Show();
After deinstalling the VSTO-Add-In: On clicking on a e-mail-notification results in an error message:
"Cannot Start Microsoft Outlook. The Command Line Argument Is Not Valid..."
It seems there are some problems with windows registry keys, especially with .msg file associations. Because when you click on a toast notification in Outlook a corresponding item is displayed/opened.
Re-associate the .msg file by following the steps and verify the results.
Click on Start and then Default Programs.
Click on Associate a file type protocol with a program option.
Select .msg from the Name list and then click on Change Program.
Now click to select Microsoft Office Outlook and then click on OK.
Restart the computer and then try opening emails saved on the Computer.
See Error: The command line argument is not valid. Verify the switch you are using. for more information.
I set up my outlook Office 365 account and I want to retrieve the emails from my outlook mailbox, earlier we were using Exchange Service in our code, but now we can't use the Exchange service anymore due to EWS his no longer available in microsoft.
Could you please help me how can I retrieve my emails in outlook office 365 account.
I am attaching a sample code that I have created but I am not able to read the emails.
In the below code, i tried to retrieve email through IMAP4 protocol server.
When i run the code, i get this error - ReceiveOutlookMail.exe' has exited with code 0 (0x0).
class Program
{
// Generate an unqiue email file name based on date time
static string _generateFileName(int sequence)
{
DateTime currentDateTime = DateTime.Now;
return string.Format("{0}-{1:000}-{2:000}.eml",
currentDateTime.ToString("yyyyMMddHHmmss", new CultureInfo("en-US")),
currentDateTime.Millisecond,
sequence);
}
static void Main(string[] args)
{
try
{
// Create a folder named "inbox" under current directory
// to save the email retrieved.
string localInbox = string.Format("{0}\\inbox", Directory.GetCurrentDirectory());
// If the folder is not existed, create it.
if (!Directory.Exists(localInbox))
{
Directory.CreateDirectory(localInbox);
}
// Hotmail/MSN IMAP4 server is "imap-mail.outlook.com"
//MailServer oServer = new MailServer("imap-server-name",
// "liveid#hotmail.com", "yourpassword", ServerProtocol.Imap4);
// For office 365 user, please change server to:
MailServer oServer = new MailServer("imap-server-name",
"test#gmail.com", "password", ServerProtocol.Imap4);
// Enable SSL connection.
oServer.SSLConnection = true;
// Set 993 SSL port
oServer.Port = 993;
MailClient oClient = new MailClient("TryIt");
oClient.Connect(oServer);
// retrieve unread/new email only
oClient.GetMailInfosParam.Reset();
oClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.NewOnly;
MailInfo[] infos = oClient.GetMailInfos();
Console.WriteLine("Total {0} unread email(s)\r\n", infos.Length);
for (int i = 0; i < infos.Length; i++)
{
MailInfo info = infos[i];
Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
info.Index, info.Size, info.UIDL);
// Receive email from IMAP4 server
Mail oMail = oClient.GetMail(info);
Console.WriteLine("From: {0}", oMail.From.ToString());
Console.WriteLine("Subject: {0}\r\n", oMail.Subject);
// Generate an unqiue email file name based on date time.
string fileName = _generateFileName(i + 1);
string fullPath = string.Format("{0}\\{1}", localInbox, fileName);
// Save email to local disk
oMail.SaveAs(fullPath, true);
// mark unread email as read, next time this email won't be retrieved again
if (!info.Read)
{
oClient.MarkAsRead(info, true);
}
// if you don't want to leave a copy on server, please use
// oClient.Delete(info);
// instead of MarkAsRead
}
// Quit and expunge emails marked as deleted from IMAP4 server.
oClient.Quit();
Console.WriteLine("Completed!");
}
catch (Exception ep)
{
Console.WriteLine(ep.Message);
}
}
}
}
string email ="sample#gmail.com";
attachment = path + "/" + filename;
Application.OpenURL ("mailto:" +
email+"
?subject=EmailSubject&body=EmailBody"+"&attachment="+attachment);
In the above code, attachment isn't working. Is there any other alternative to add attachments using a mailto: link in C#?
mailto: doesn't officially support attachments. I've heard Outlook 2003 will work with this syntax:
<a href='mailto:name#domain.com?Subject=SubjTxt&Body=Bod_Txt&Attachment=""C:\file.txt"" '>
Your problem has already been answered:
c-sharp-mailto-with-attachment
You can use the System.Net.Mail which has the MailMessage.Attachments Property. Something like:
message.Attachments.Add(new Attachment(yourAttachmentPath));
OR
You can try like this:
using SendFileTo;
namespace TestSendTo
{
public partial class Form1 : Form
{
private void btnSend_Click(object sender, EventArgs e)
{
MAPI mapi = new MAPI();
mapi.AddAttachment("c:\\temp\\file1.txt");
mapi.AddAttachment("c:\\temp\\file2.txt");
mapi.AddRecipientTo("person1#somewhere.com");
mapi.AddRecipientTo("person2#somewhere.com");
mapi.SendMailPopup("testing", "body text");
// Or if you want try and do a direct send without displaying the
// mail dialog mapi.SendMailDirect("testing", "body text");
}
}
}
The above code uses the MAPI32.dll.
Source
It probably won't attach the document because you are at the liberty
of the email client to implement the mailto protocol and include
parsing for the attachment clause. You may not know what mail client
is installed on the PC, so it may not always work - Outlook certainly
doesn't support attachments using mailto.
A better way to handle this is to send the mail on the server using System.Net.Mail.Attachment.
public static void CreateMessageWithAttachment(string server)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
string file = "data.xls";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"jane#contoso.com",
"ben#contoso.com",
"Quarterly data report.",
"See the attached spreadsheet.");
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}", ex.ToString());
}
data.Dispose();
}
I want to count the number of emails I have in my GMail inbox using IMAPX. Here is what I have written so far:
if (client.Connect()) {
Console.WriteLine("Connected Successfully.");
if (client.Login("MyEmai, "MyPassword")) {
Folder inbox = client.Folders.Inbox;
int count = inbox.Messages.Count();
Console.WriteLine("Total Items:" + count.ToString());
}
}
But it is always returning 0 as output. I'm using Version 3.5 of the IMAPX 2.
By default, the Folder.Messages collection is not being filled. If you want to let the client download the messages automatically, configure the client do do this:
var client = new ImapClient("imap.gmail.com", true);
client.Behavior.AutoPopulateFolderMessages = true;
However, it's often better to make a call to Folder.Messages.Download instead or use Folder.Search
Documentation about message download mode..
I've recently designed a program in C# that will pull information from SQL databases, write an HTML page with the results, and auto-email it out. I've got everything working [sporadically], the problem I'm having is that I seem to be crashing our company's exchange server. After the first few successful runs of the program, I'll start getting this exception:
Base exception: System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Insufficient system resources
I'm wondering if I should be calling some sort of Dispose()-like method in my mailing? Or if there is any other apparent reason that I would be causing the mail system to stop responding? This affects all clients in our company, not just my code.
This is Exchange 2010, and my code is compiled against .NET 3.5. My attachments are typically 27kb. If I log into the exchange server, it seems that messages just stick in a queue indefinitely. Clearing out the queue (remove without sending NDR) and rebooting the server will get it going again.
The mailing portions look like this (username, password, and address changed):
public void doFinalEmail()
{
List<string> distList = new List<string>();
string distListPath = Environment.CurrentDirectory + "\\DistList.txt";
string aLine;
logThat("Attempting email distribution of the generated report.");
if (File.Exists(distListPath))
{
FileInfo distFile = new FileInfo(distListPath);
StreamReader distReader = distFile.OpenText();
while (!String.IsNullOrEmpty(aLine = distReader.ReadLine()))
{
distList.Add(aLine);
}
}
else
{
logThat("[[ERROR]]: Distribution List DOES NOT EXIST! Path: " + distListPath);
}
MailMessage msg = new MailMessage();
MailAddress fromAddress = new MailAddress("emailaddresshere");
msg.From = fromAddress;
logThat("Recipients: ");
foreach (string anAddr in distList)
{
msg.To.Add(anAddr);
logThat("\t" + anAddr);
}
if (File.Exists(Program.fullExportPath))
{
logThat("Attachment: " + Program.fullExportPath);
Attachment mailAttachment = new Attachment(Program.fullExportPath);
msg.Attachments.Add(mailAttachment);
string subj = "Company: " + Program.yestFileName;
msg.Subject = subj;
msg.IsBodyHtml = true;
msg.BodyEncoding = System.Text.Encoding.UTF8;
sendMail(msg);
}
else
{
logThat("[[ERROR]]: ATTACHMENT DOES NOT EXIST! Path: " + Program.fullExportPath);
}
}
public void sendMail(MailMessage msg)
{
try
{
string username = "user"; //domain user
string password = "pass"; // password
SmtpClient mClient = new SmtpClient();
mClient.Host = "192.168.254.11";
mClient.Credentials = new NetworkCredential(username, password);
mClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mClient.Send(msg);
}
catch (Exception oops)
{
string whatHappened = String.Format("Company: \r\nFailure in {0}! \r\n\r\nError message: {1} \r\nError data: {2} \r\n\r\nStack trace: {3} \r\n\r\nBase exception: {4} \r\nOccuring in method: {5} with a type of {6}\r\n", oops.Source, oops.Message, oops.Data, oops.StackTrace, oops.GetBaseException(), oops.TargetSite, oops.GetType());
logThat(whatHappened);
Environment.Exit(1);
}
}
This error can happen when:
The exchange server is out of disk space.
The recipient mailbox is out of disk space.
It is more common to run into issue #2 than issue #1.
Here is a list of Exchange Status Codes and their meanings.
To narrow down the issue definitively, you could swap in a different mail client like aspNetEmail (you can get an eval version to test), it wouldn't take but a few lines of code. If the problem persists, it is on the server; if not, it is on the client. I would strongly suspect this is a problem on the server, however, as when the client closes the connection and the message is sent, the server should really not be holding any resources as a result of that connection. You could verify this by looking at your SMTP logs and making sure there was no SMTP error when the connection was closed.
If this is indeed a problem on the server (the SMTP log shows clean disconnection and the problem is replicable with an alternate client), then I would log onto the server (if you can get access), and watch the disk space as jeuton suggests.
In exchange 2007 the c: (system drive) needs about 4GB of free disk space. This was our problem. Increment the drive and the mails will flow again.