Hi I believe I am pretty close to figuring out what is wrong with my code, but was hoping someone could help me out or point me in the right direction. I am able to run my program and on the page where the user is going to be uploading a file it gives me the option to choose a file. But when I press submit other information gets sent to me but the file never comes. I think this is because I am having trouble figuring out where to temporarily save the file when it send to my email. Here is my code at the moment:
Also what this code is for is a comment / request page on my website where the user can comment and also add a screen shot.
private string SendMessage(string strTo, string strFrom, string strSubject, string strMessage, string strAttachment, string strBCC)
{
try
{
MailMessage mailMsg;
string strEmail = "";
string strSmtpClient = ConfigurationManager.AppSettings["SmtpClient"];
string[] arrEmailAddress = strTo.Split(';');
for (int intCtr = 0; intCtr < arrEmailAddress.Length; intCtr++)
{
strEmail = "";
if (arrEmailAddress[intCtr].ToString().Trim() != "")
{
strEmail = arrEmailAddress[intCtr].ToString().Trim();
mailMsg = new MailMessage(strFrom, strEmail, strSubject, strMessage);
mailMsg.IsBodyHtml = true;
if (!strBCC.Trim().Equals(string.Empty))
mailMsg.Bcc.Add(strBCC);
SmtpClient smtpClient = new SmtpClient(strSmtpClient);
smtpClient.UseDefaultCredentials = true;
smtpClient.Port = 25;
smtpClient.Send(mailMsg);
mailMsg.Dispose();
}
}
return "Message sent to " + strTo + " at " + DateTime.Now.ToString() + ".";
}
catch (Exception objEx)
{
return objEx.Message.ToString();
}
string strUpLoadDateTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
string strFileName1 = string.Empty;
if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
{
string strUploadFileName1 = File1.PostedFile.FileName;
strFileName1 = strUpLoadDateTime + "." + Path.GetFileNameWithoutExtension(strUploadFileName1) + Path.GetExtension(strUploadFileName1);
strFileName1 = strFileName1.Replace("'", "");
string strSaveLocation = Server.MapPath("") + "\\" + strFileName1;
File1.PostedFile.SaveAs(strSaveLocation);
txtComments.Text = "The file has been uploaded";
}
My question is where am I going wrong where in this code do I put where I want the file to be saved.
The below part of the code is what I am using to format the email when it is sent. And pick what will be sent in the email.
protected void Submit_Click1(object sender, EventArgs e)
{
try
{
string dandt = System.DateTime.Now.ToString("yyyyMMddHHmmss");
string strMessage = "Bug Name: " + txtBugName.Text.Trim() + "<br/>" +
"Module Name: " + ddlModule.SelectedValue + "<br/>" +
"Page Name: " + ddlPage.SelectedValue + "<br/>" +
"Description: " + txtComments.Text.Trim() + "<br/>" +
File1.f + "<br/>" +
"Email is" + " " + txtemail.Text.Trim() + "<br/>" +
"The request was sent at" + dandt;
SendMessage(ConfigurationManager.AppSettings["EmailAddrTo"],
ConfigurationManager.AppSettings["EmailAddrFrom"],
txtBugName.Text.Trim(),
strMessage, "", "");
}
catch
{
}
}
For some reason now nothing is sending in my emails when I press submit. Also I was trying to figure out how to put in the email the time and date the email was sent. Even though obviously my email will have this information, incase the email is delayed for some reason I would like to have the time and date the user pressed the submit button. Where is says File.F in this part of the code this is where i was trying to figure out how to get the file attachment to go to the email, but I'm not sure what syntax should go there in the code.
It looks like you are trying to attach some file from the user's computer to the email you are sending. If that is the case, you need to upload your file first before you call SendMessage.
In your Submit_Click the first thing you need to do is the code the uploads the file somewhere. Also, remove that File1.f from strMessage which is where I suspect is causing your message to null out on you.
After you upload your file, pass strSavedLocation, which is the file location you saved the file, to your SendMessage() method.
In your SendMessage method you can attach the file with the following code where you are buliding your MailMessage. strAttachment is the path name to your uploaded file:
var attachment = new Attachment(strAttachment);
// Add time stamp information for the file.
ContentDisposition disposition = attachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(strAttachment);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(strAttachment);
disposition.ReadDate = System.IO.File.GetLastAccessTime(strAttachment);
mailMsg.Attachments.Add(attachment);
It looks to me like you have the major parts here minus the handy, System.Net.Mail.Attachment.
If I were doing this, I'd move the file upload handling code into the Submit_Click handler, and then just add the Mail.Attachment code.
private string SendMessage(string strTo, string strFrom, string strSubject, string strMessage, string strAttachment, string strBCC)
{
try
{
System.Net.Mail.MailMessage mailMsg;
string strEmail = "";
string strSmtpClient = ConfigurationManager.AppSettings["SmtpClient"];
string[] arrEmailAddress = strTo.Split(';');
for (int intCtr = 0; intCtr < arrEmailAddress.Length; intCtr++)
{
strEmail = "";
if (arrEmailAddress[intCtr].ToString().Trim() != "")
{
strEmail = arrEmailAddress[intCtr].ToString().Trim();
mailMsg = new MailMessage(strFrom, strEmail, strSubject, strMessage);
mailMsg.IsBodyHtml = true;
if (!strBCC.Trim().Equals(string.Empty))
mailMsg.Bcc.Add(strBCC);
/*** Added mail attachment handling ***/
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(strAttachment);
mailMsg.Attachments.Add(attachment);
SmtpClient smtpClient = new SmtpClient(strSmtpClient);
smtpClient.UseDefaultCredentials = true;
smtpClient.Port = 25;
smtpClient.Send(mailMsg);
mailMsg.Dispose();
}
}
return "Message sent to " + strTo + " at " + DateTime.Now.ToString() + ".";
}
catch (Exception objEx)
{
return objEx.Message.ToString();
}
}
protected void Submit_Click1(object sender, EventArgs e)
{
try
{
/*** Moved from SendMessage function ****/
string strUpLoadDateTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
string strFileName1 = string.Empty;
if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
{
string strUploadFileName1 = File1.PostedFile.FileName;
strFileName1 = strUpLoadDateTime + "." + Path.GetFileNameWithoutExtension(strUploadFileName1) + Path.GetExtension(strUploadFileName1);
strFileName1 = strFileName1.Replace("'", "");
string strSaveLocation = Server.MapPath("") + "\\" + strFileName1;
File1.PostedFile.SaveAs(strSaveLocation);
txtComments.Text = "The file has been uploaded";
}
string dandt = System.DateTime.Now.ToString("yyyyMMddHHmmss");
string strMessage = "Bug Name: " + txtBugName.Text.Trim() + "<br/>" +
"Module Name: " + ddlModule.SelectedValue + "<br/>" +
"Page Name: " + ddlPage.SelectedValue + "<br/>" +
"Description: " + txtComments.Text.Trim() + "<br/>" +
strSaveLocation + "<br/>" +
"Email is" + " " + txtemail.Text.Trim() + "<br/>" +
"The request was sent at" + dandt;
SendMessage(ConfigurationManager.AppSettings["EmailAddrTo"],
ConfigurationManager.AppSettings["EmailAddrFrom"],
txtBugName.Text.Trim(),
strMessage, strSaveLocation, "");
}
catch
{
}
}
As for the note about using StringBuilder, I agree, and I would use it like this:
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendFormat("Bug Name: {0}<br/>", txtBugName.Text.Trim());
sb.AppendFormat("Module Name: {0}<br/>", ddlModule.SelectedValue);
Edited To Add:
Also, see Brad's answer above about using ContentDisposition.
Related
I have a method to be able to share images through SMS, WhatsApp, Email, Fb, etc., to which when calling it a URL is passed.
The method downloads the image from the shared URL and the image is ready to send (Xamarin.Essentials.Share is used).
The problem is that I pass a text along with the image (need to give some context) as part of the method property, but the text does not show it to me at the time of sharing, only the image alone, and it does not serve me well since it would send it without any context or information.
Any other ideas on how to pass the image and a text on Android?
Maybe some kind of automatic copy and then paste some text to the keyboard clipboard?
Image and Text Method:
public async Task DownloadImageAndShareIt(string URL)
{
try
{
string localPath = "";
var webClient = new WebClient();
webClient.DownloadDataCompleted += (s, e) =>
{
byte[] bytes = new byte[e.Result.Length];
bytes = e.Result; // get the downloaded data
string documentsPath = Android.OS.Environment.GetExternalStoragePublicDirectory
(Android.OS.Environment.DirectoryPictures).AbsolutePath;
var partedURL = URL.Split('/');
string localFilename = partedURL[partedURL.Length - 1];
localFilename = "MyAPP" + localFilename;
localPath = System.IO.Path.Combine(documentsPath, localFilename);
File.WriteAllBytes(localPath, bytes); // writes to local storage
MediaScannerConnection.ScanFile(Application.Context, new string[] { localPath }, null, null);
};
var url = new Uri(URL);
webClient.DownloadDataAsync(url);
var partedURL = URL.Split('/');
string localFilename = partedURL[partedURL.Length - 1];
localFilename = "MyAPP" + localFilename;
string documentsPath = Android.OS.Environment.GetExternalStoragePublicDirectory
(Android.OS.Environment.DirectoryPictures).AbsolutePath;
localPath = System.IO.Path.Combine(documentsPath, localFilename);
//Done.
}
catch (Exception Ex)
{
string LineErrorNumber = "Error line: " + Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7) + "\r\n" + "Error: " + Ex.Message;
}
finally
{
await Share.RequestAsync(new ShareFileRequest
{
Title = **"Delicate info from MyAPP"**,
File = new ShareFile(localPath)
});
}
}
It should be noted that if I use another Share method that is only for text, there if I share it without problems.
Text only Method:
private async Task ShareText(string Tipo, string Titulo, string ContenidoaCompartir)
{
try
{
await Share.RequestAsync(new ShareTextRequest
{
Uri = "Delicate info from MyAPP",
Title = Titulo,
Subject = (Tipo + " de " + Titulo).ToString(),
Text = "MyApp - " + Tipo + " de " + Titulo + ":" + System.Environment.NewLine + ContenidoaCompartir + System.Environment.NewLine
});
}
catch (Exception Ex)
{
string LineErrorNumber = "Error line: " + Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7) + "\r\n" + "Error: " + Ex.Message; Crashes.TrackError(Ex);
}
}
You can check the question below which shows how to share text and image through whatsapp Share image and text through Whatsapp or Facebook
I have a C# Winforms application I'm working on in Visual Studio 2010, the page in question is a bug reporting form - I have all the details set, email sends fine etc. My issue is attaching a screenshot to the email in the body, I have code set up to allow users to find and select a screenshot they take and attach to the form, but in the body itself it just gives me the text "System.Windows.Forms.Picturebox", or various similarities to that if I try .image.
I've had a look around via Google and here, but can only find topics that are to do with embedding the image or attaching it (and thus require to enter in a specific folder/image etc), whereas my users will be attaching their own image and name from different places. Is there anyway to get the image to be picked up without having to hardcode a location and name that my users will have to follow each time?
Code below:
private void btnBugEmail_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
SmtpClient client = new SmtpClient("details here");
MailMessage message = new MailMessage();
message.From = new MailAddress("email here");
string mailBox = txtBugAdd.Text.Trim();
message.To.Add(mailBox);
string mailFrom = txtEmailFromBug.Text.Trim();
message.CC.Add(mailFrom);
string mailCC = txtMailCCBug.Text.Trim();
message.Bcc.Add(mailCC);
message.IsBodyHtml = true;
message.Body = "Bug Report - please see below: " +
"\n" + "<br>" + "<b>" + "1. What were you doing at the time of the error?" + "</b>" +
"\n" + "<br>" + rtbTimeOfError.Text +
"\n" + "<br>" + "<b>" + "2. Are you able to repeat the steps and achieve the same error?" + "</b>" +
"\n" + "<br>" + rtbCanRepeat.Text +
"\n" + "<br>" + "<b>" + "3. Does this problem happen again if you change any of the details you have entered?" + "</b>" +
"\n" + "<br>" + rtbChangeDetails.Text;
message.Subject = "Bug Report";
var image = pboxBugImage.Image;
using(var ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Jpeg);
message.Attachments.Add(new Attachment(ms, "Screenshot.jpg"));
client.Credentials = new System.Net.NetworkCredential("credentials here");
client.Port = System.Convert.ToInt32(25);
client.Send(message);
}
new Endpage().Show();
this.Close();
}
catch
{
MessageBox.Show("my comment here");
}
}
Take a look to the following link
system.net.mail.mailmessage.attachments
You cannot put a winforms control inside the mailmessage :) it is outputted with ToString()... that is what you see in mail
Example
private void btnBugEmail_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
SmtpClient client = new SmtpClient("details here");
MailMessage message = new MailMessage();
message.From = new MailAddress("email here");
string mailBox = txtBugAdd.Text.Trim();
message.To.Add(mailBox);
string mailFrom = txtEmailFromBug.Text.Trim();
message.CC.Add(mailFrom);
string mailCC = txtMailCCBug.Text.Trim();
message.Bcc.Add(mailCC);
message.IsBodyHtml = true;
message.Body = "Bug Report - please see below: " +
"\n" + "<br>" + "<b>" + "1. What were you doing at the time of the error?" + "</b>" +
"\n" + "<br>" + rtbTimeOfError.Text +
"\n" + "<br>" + "<b>" + "2. Are you able to repeat the steps and achieve the same error?" + "</b>" +
"\n" + "<br>" + rtbCanRepeat.Text +
"\n" + "<br>" + "<b>" + "3. Does this problem happen again if you change any of the details you have entered?" + "</b>" +
"\n" + "<br>" + rtbChangeDetails.Text;
message.Subject = "Bug Report";
var image = pboxBugImage.Image;
using(var ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Jpeg);
message.Attachments.Add(new Attachment(ms, "Screenshot.jpg"));
client.Credentials = new System.Net.NetworkCredential("credentials here");
client.Port = System.Convert.ToInt32(25);
client.Send(message);
}
new Endpage().Show();
this.Close();
}
catch
{
MessageBox.Show("my comment here");
}
}
Take a look at your resources and dispose the memorystream. I didnt for the example, because i wrote it here in editor
How I can create a email attachment in C# and asp.net. I want use a html file that describe the attachment and I want it load in a kind of a message string in my application. Than I want do replace substrings in this message with other values that I get from a database. If the attachment is create I want to send it to a address.
I use a helpclass now but I think it is not the right way :/
I don't know whether it exist in .net libary. a kind of class or something.
What is the best way to do it?
here is the method how I make it now: namespave = using SmtpMail = EASendMail.SmtpMail;
private void SendMail(string vorname, string nachname, string anrede, string firma, string benutzername, string passwort, string von, string bis, string email)
{
SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
oMail.From = email;
oMail.To = email;
oMail.Subject = "Company (" + nachname + ", " + vorname + ")";
SmtpServer oServer = new SmtpServer(SMTPSERVER);
try
{
Attachment header = oMail.AddAttachment(Properties.Settings.Default.ATT_header);
Attachment footer = oMail.AddAttachment(Properties.Settings.Default.ATT_footer);
Attachment left = oMail.AddAttachment(Properties.Settings.Default.ATT_left);
Attachment right = oMail.AddAttachment(Properties.Settings.Default.ATT_right);
Attachment world = oMail.AddAttachment(Properties.Settings.Default.ATT_world);
Attachment company = oMail.AddAttachment(Properties.Settings.Default.ATT_company);
Attachment weltkarte_header = oMail.AddAttachment(Properties.Settings.Default.ATT_weltkarte);
string contentID_header = "header";
header.ContentID = contentID_header;
string contentID_footer = "footer";
footer.ContentID = contentID_footer;
string ContentID_left = "left";
left.ContentID = ContentID_left;
string ContentID_right = "right";
right.ContentID = ContentID_right;
string ContentID_world = "world";
world.ContentID = ContentID_world;
string ContentID_company = "company";
company.ContentID = ContentID_company;
string ContentID_weltkarte_header = "weltkarte_header";
weltkarte_header.ContentID = ContentID_weltkarte_header;
string htmltext = "<html><body><table width='1000px' border='0' cellpadding='0' cellspacing='0'>" +
"<tr><img src=\"cid:" + contentID_header + "\"></tr>" +
"<tr><img src=\"cid:" + ContentID_weltkarte_header + "\"></tr>" +
"<tr><table border='0' cellpadding='0' cellspacing='0'>" +
"<tr>" +
"<td><img src=\"cid:" + ContentID_left + "\"></td>" +
"<td width='880' style='background-color:#efefef;'>" +
"<p align='center'>Sie haben einen Gastzugang für [Anrede] [Vorname] [Nachname],[Firma] eingerichtet.</p>" +
"<p align='center'>Im folgenden finden Sie die Zugangsdaten,</br>" +
"die für die Anmeldung am Netzwerk benötigt werden.Weitere Informationen stehen auf der Anmeldeseite zur Verfügung.</p>" +
"<p align='center'><b>Benutzername: [Benutzername]</b><br/><b>Kennwort: [Passwort]</b></p>" +
"<p align='center'>Der Zugang wird vom [ZeitVon] bis [ZeitBis] freigeschaltet sein.</p>" +
"</td>" +
"<td><img src=\"cid:" + ContentID_right + "\"></td>" +
"</tr>" +
"</table></tr>" +
"<tr><img src=\"cid:" + ContentID_company + "\"></tr>" +
"<tr><img src=\"cid:" + contentID_footer + "\"></tr>" +
"</table></body></html>";
htmltext = htmltext.Replace("[Anrede]", anrede).Replace("[Vorname]", vorname).Replace("[Firma]", firma).Replace("[Nachname]", nachname);
htmltext = htmltext.Replace("[Benutzername]", benutzername).Replace("[Passwort]", passwort);
htmltext = htmltext.Replace("[ZeitVon]", von).Replace("[ZeitBis]", bis);
oMail.HtmlBody = htmltext;
oSmtp.SendMail(oServer, oMail);
}
catch (Exception)
{
}
}
UPDATE:
Now I have create a html file with images but I bind this images with base64 coding. it works but if I read this html in the c# application I don't can send this mail. I make a breakepoint and look in my readstring but it is all right :/
here the code:
...
SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
oMail.From = mail;
oMail.To = mail;
oMail.Subject = "company (" + lastname + ", " + firstname + ")";
SmtpServer oServer = new SmtpServer(SMTPSERVER);
try
{
using (StreamReader reader = new StreamReader(Server.MapPath("~/App_Data/zugangsmail.html"), System.Text.Encoding.Default))
{
string message = reader.ReadToEnd();
message = message.Replace("[Anrede]", title).Replace("[Vorname]", firstname).Replace("[Firma]", company).Replace("[Nachname]", lastname);
message = message.Replace("[Benutzername]", username).Replace("[Passwort]", password);
message = message.Replace("[ZeitVon]", from).Replace("[ZeitBis]", to);
oMail.HtmlBody = message;
oSmtp.SendMail(oServer, oMail);
}
}
catch (Exception ex)
{
error.Visible = true;
lblErrorMessage.Text = ex.Message;
}
...
Add the file as an embedded resource.
Open it and read the content
Send the content.
var assembly = Assembly.GetExecutingAssembly();
using (var stream = asssembly.GetManifestResourceStream("namespace.folder.filename))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}
i had a problem in format in email. I want to have a new line..
here's the format in email..
Name: sdds Phone: 343434 Fax: 3434 Email: valencia_arman#yahoo.com Address: dsds Remarks: dsds Giftwrap: Yes Giftwrap Instructions: sdds Details: PEOPLE OF THE BIBLE(SCPOTB-8101-05) 1 x Php 275.00 = Php 275.00 Total: Php275.00
here's my C# code..
mail.Body = "Name: " + newInfo.ContactPerson + Environment.NewLine
+ "Phone: " + newInfo.Phone + Environment.NewLine
+ "Fax: " + newInfo.Fax + Environment.NewLine
+ "Email: " + newInfo.Email + Environment.NewLine
+ "Address: " + newInfo.Address + Environment.NewLine
+ "Remarks: " + newInfo.Notes + Environment.NewLine
+ "Giftwrap: " + rbGiftWrap.SelectedValue + Environment.NewLine
+ "Giftwrap Instructions: " + newInfo.Instructions + Environment.NewLine + Environment.NewLine
+ "Details: " + Environment.NewLine
+ mailDetails;
If you're sending it in HTML, make sure you set the format.
mail.BodyFormat = MailFormat.Html;
And then you can use <br/> should you want to.
UPDATE:
Try this as an alternative:
using System.Net.Mail;
...
MailMessage myMail;
myMail = new MailMessage();
myMail.IsBodyHtml = true;
maybe you can try this...
We create seperate email templates (e.g. EmailTemplate.htm), it includes the message to be sent. You will have no problems for new line in message.
Then this is our Code behind:
private void SendEmail()
{
string emailPath = "../EmailTemplate.htm"; //Define your template path here
string emailBody = string.Empty;
StreamReader sr = new StreamReader(emailPath);
emailBody = sr.ReadToEnd();
sr.Close();
sr.Dispose();
//Send Email; you can refactor this out
MailMessage message = new MailMessage();
MailAddress address = new MailAddress("sender#domain.com", "display name");
message.From = address;
message.To.Add("to#domain.com");
message.Subject = "Your Subject";
message.IsBodyHtml = true; //defines that your email is in Html form
message.Body = emailBody;
//smtp is defined in web.config
SmtpClient smtp = new SmtpClient();
try
{
smtp.Send(message);
}
catch (Exception ex)
{
//catch errors here...
}
}
Did you try "+\n" instead of Environment.NewLine?
I'm using Redemption dll (http://www.dimastr.com/redemption/) and I've created an exe that accesses my mail box.
I run the exe in Windows Scheduler under my username and it works fine, I get an email sent to me (see below code).
When I change the runas username in Scheduler to someone else and try to access their mail box Profile I get an error. System.IO.FileLoadException
static void Main(string[] args)
{
System.Diagnostics.Debugger.Break();
object oItems;
//string outLookUser = "My Profile Name";
string outLookUser = "Other User Profile Name";
string ToEmailAddress = "abc.email#xyz.com";
string FromEmailAddress = "abc.email#xyz.com";
string outLookServer = "exchangeServer.com";
string sMessageBody =
"\n outLookUser: " + outLookUser +
"\n outLookServer: " + outLookServer +
"\n\n";
RDOSession Session = null;
try
{
rdoDefaultFolders olFolderInbox = rdoDefaultFolders.olFolderInbox;
Session = new RDOSession();
RDOFolder objFolder;
Session.LogonExchangeMailbox(outLookUser, outLookServer);
int mailboxCount = Session.Stores.Count;
string defaultStore = Session.Stores.DefaultStore.Name;
sMessageBody +=
"\n mailboxCount: " + mailboxCount.ToString() +
"\n defaultStore: " + defaultStore +
"\n\n";
//RDOStore rmpMetering = Session.Stores.GetSharedMailbox("Name of another mailbox");
//objFolder = rmpMetering.GetDefaultFolder(olFolderInbox);
objFolder = Session.GetDefaultFolder(olFolderInbox);
oItems = objFolder.Items;
int totalcount = objFolder.Items.Count;
if (totalcount > 10) totalcount = 10;
for (int loopcounter = 1; loopcounter < totalcount; loopcounter++)
{
RDOMail oItem = objFolder.Items[loopcounter];
string attachmentName = string.Empty;
foreach (RDOAttachment attachment in oItem.Attachments)
{
attachmentName += attachment.FileName + " ";
if (attachmentName.Trim() == "Data.csv")
{
attachment.SaveAsFile(#"C:\datafiles\" + attachmentName.Trim());
foreach (RDOFolder archiveFolder in objFolder.Folders)
{
if (archiveFolder.Name == "DataFileArchive")
{
oItem.MarkRead(true);
oItem.Move(archiveFolder);
}
}
}
}
sMessageBody += oItem.Subject + " " + attachmentName + "\n";
if ((oItem.UnRead))
{
//Do whatever you need this for
//sMessageBody = oItem.Body;
//oItem.MarkRead(true);
}
}
System.Web.Mail.SmtpMail.Send(ToEmailAddress,FromEmailAddress
, "Data File Processing-" + DateTime.Now.ToString()
,"" + sMessageBody);
}
catch (Exception ex)
{
Session = null;
System.Web.Mail.SmtpMail.Send(ToEmailAddress, FromEmailAddress, "Error", sMessageBody + " " + ex.Message);
}
finally
{
if ((Session != null))
{
if (Session.LoggedOn)
{
Session.Logoff();
}
}
}
}
When I try to run the same exe on another machine with me logged in I get this error,
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'Interop.Redemption, Version=4.7.0.0, Culture=neutral, PublicKeyToken=null
' or one of its dependencies. The system cannot find the file specified.
File name: 'Interop.Redemption, Version=4.7.0.0, Culture=neutral, PublicKeyToken
=null'
at RPMDataFileProcessing.Program.Main(String[] args)
Has anyone got any ideas on what I'm doing wrong, can Redemption be used in this way?
I got this working in the end by ensuring that the user you are logged in as, has 'full mailbox rights' to the mail box you are trying to see.