mailItem.HTMLBody = "Dear IT Dept. You have received a new "+ comboBox3.Text + " priority task to complete from " + textBox1.Text + ". Please save the attached file and fit the task in to your schedule. Once completed please contact the " + textBox2.Text + " for comfirmation the task is completed to thier expectations. The Task is as follows: " + richTextBox1.Text + " Kind Regards, " + textBox1.Text + "";
I basically want to highlight the text/combo boxes or at least change their font color. Annoyingly you can't see the html code I used but it should be pretty obvious but I tried using the font color...with no luck. can't see where I'm going wrong
I can see that you try to put value of textBox2.txt. Your mistake is that wrote textBox2.txt as a string content. So you can achive this with using string.Format method.
You should to change it with this:
mailItem.HTMLBody = string.Format("<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from ({0}) Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>", textBox2.Text);
Notice that textBox2.Text and {0} element.
Note: You also wrong with syntax of TextBox.Text property.
You need to have:
mailItem.HTMLBody = "<html><body>... from " + textBox2.Text + " Please ...";
instead of
mailItem.HTMLBody = "<html><body>... from (textBox2.txt) Please ...";
There is no HTMLBody property on the MailMessage class (assuming this is what you're using?).
It's just Body.
You would do something like this:
mailItem.Body = string.Format("<html><body><p>Dear {0}.</p>", comboBox3.Text);
Etc...
var mailItem= new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp server addess");
mailItem.From = new MailAddress("your_email_address#xyz.com");
mailItem.To.Add("it-department#???.co.uk");
mailItem.Subject = string.Format("You have a new task from {0}", comboBox3.Text);
mailItem.To = "";
mailItem.Body =string.Format("<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from {0} Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to their expectations.</p>",textBox2.txt);
attachment = new System.Net.Mail.Attachment(#"\\??-filesvr\shares\Shared\+++++Web Projects+++++\????\IssueReport.txt");
mailItem.Attachments.Add(#"\\??-filesvr\shares\Shared\+++++Web Projects+++++\??\IssueReport.txt");
mailItem.IsBodyHtml = true;
// Optional Items based on your smtp server.
/* SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;*/
SmtpServer.Send(mailItem);
MessageBox.Show("mail Send");
Did you mean :
mailItem.HTMLBody = "<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from " + textBox2.Text + " Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>";
?
In your version, "textbox2.txt" will be manipulated as a string, it won't be "parsed".
In mine it's a control on your form and we put its text content in the mail.
Edit : you asked how to emphase the variable, here is a example :
Try something like
mailItem.HTMLBody = "<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from <strong>" + textBox2.Text + "</strong> Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>";
The "strong" tag around your variable will put the name in bold.
Related
I would like to use gammu to send text messages with address and message, but I have a problem with the gammu parameters. If I start only the program it runs (string cmd1 = "c:\\G133\\bin\\gammu.exe ";). After adding parameters it gives this failure:
System.ComponentModel.Win32Exception' occurred in System.dll
Additional information: The system cannot find the file specified:
Code:
string[] sms = File.ReadAllLines(#"C:\\temp\\test.txt");
string address = sms[0];
string message = sms[1];
string cmd1 = #"C:\G133\bin\gammu.exe --sendsms TEXT" + " " +
"\"" + address + "\" -text " + " " + "\"" + message + "\"";
System.Diagnostics.Process.Start(cmd1);
Can anyone help me? Thanks in advance.
The output looks well:
Console.WriteLine(cmd1); - result
C:\G133\bin\gammu.exe --sendsms TEXT +12121234567 -text "Hello"
You need to call the overload of Start method which takes two parameters:
First one: the file to run;
Second one: the parameters
And it will looks like:
string app = #"path\to\your\target\app";
string prms = "your parameters";
System.Diagnostics.Process.Start(app, prms);
You should split the application and the arguments:
Process.Start(#"C:\G133\bin\gammu.exe", "--sendsms TEXT +12121234567 -text \"Hello\"");
So, for a few days i've been trying to do this, still, i've passed trough a few problems but im stuck on this one. looks like my connection to AD is working fine (after alot of digging and googling)
i have this.
I'm not a developer, still i have studied c# in school and i have some knowledge of it, still, i need to make this work in order to save time when it comes the time to create a new user.
private void btn_create_Click(object sender, EventArgs e)
{
bool valid = false;
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "PTLISDC04", "Users");
{
valid = ctx.ValidateCredentials("myadminaccount", "mypassword");
}
UserPrincipal usr = new UserPrincipal(ctx);
usr.UserPrincipalName = tb_user.Text.ToString() + "#kpmg.com";
usr.Name = tb_lname.Text.ToString() + ", " + lb_fname.Text.ToString() + " " + lbl_mname.Text.ToString();
usr.Description = tb_empid.Text.ToString();
usr.EmailAddress = tb_email.Text.ToString();
usr.DisplayName = tb_lname.Text.ToString() + ", " + lb_fname.Text.ToString() + " " + lbl_mname.Text.ToString();
usr.Save();
usr.Dispose();
ctx.Dispose();
MessageBox.Show("User Created!");
and when i press the "create user" button i get this:
An unhandled exception of type
'System.DirectoryServices.AccountManagement.PrincipalOperationException'
occurred in System.DirectoryServices.AccountManagement.dll
Additional information: An invalid dn syntax has been specified.
and it points to this line on code
usr.UserPrincipalName = tb_user.Text.ToString() + "#kpmg.com";
if i comment this line it goes to the next and so on
I use a very simple code to generate emails using outlook in my c# application. It works fine when Outlook is already opened.(Even though it asks for permission to open the email.But after I grant access a new Outlook message window opens with the generated email). But the real problem is if Outlook is not opened the application crashes at the line
Microsoft.Office.Interop.Outlook.Recipient oTORecipt = oMsg.Recipients.Add(email);
ERROR:An exception (first chance) of type 'System.Runtime.InteropServices.COMException' occurred in Birthday_Mailing.dll.
Additional information: discontinued operation (Exception from HRESULT: 0x80004004 (E_ABORT))
If a handler is available for this exception, the program may continue to run safely.
And my whole code can be seen as below
public void SendMail(string email, string name)
{
//// Create the Outlook application by using inline initialization.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
////Create the new message by using the simplest approach.
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Recipient oTORecipt = oMsg.Recipients.Add(email); //oRecips.Add(t);
oTORecipt.Type = (int)Microsoft.Office.Interop.Outlook.OlMailRecipientType.olTo;
oTORecipt.Resolve();
oMsg.Subject = "Herzlichen Glückwunsch";
oMsg.HTMLBody = "<html>" +
"<head>" +
"<title>Happy Birthday</title>" +
"</head>" +
"<body style='background-color:#E6E6E6;'>" +SelectImage+
"<div style='font-family: Georgia, Arial; font-size:14px; '>Liebe/r " + " " +
name + ",<br /><br />" +
"alles Gute zum <b>Geburtstag!</b> Wir wünschen einen schönen Tag und für das kommende Jahr Gesundheit, Glück und Erfolg." +
"<br /><br /><br /><br /><br />" +
"Mit den besten Grüßen,<br />" +
"XXYYZZ" +
"</div>" +
"</body>" +
"</html>";
oMsg.Save();
oMsg.Display();
oMsg = null;
oApp = null;
I'm not an expert in coding. Can someone help me to find where the actual problem is? Thanks in advance!
Microsoft.Office.Interop.Outlook.Inspector oInspector = oMsg.GetInspector;
I added this one line after declaring oMsg Object which solved the problem. But still before the message window opens Outlook asks for the users permission to display the email.
***Yet I wouldn't mark this as the Answer because it's not the best solution you can give for this question.
UPDATE: I found out that the above mentioned issue was due to some security system in our server. This is the correct answer. Thanks to #MikeMiller for showing the correct path
I have a program that sends an email with attachments, it works fine at home with a good internet connection but times out when I use a slower connection.
Does anyone know if I can extend the time out so it will send over a slower network.
The code I use is
Cursor.Current = Cursors.WaitCursor;
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(FilePaths.Default.SquadronEmailAddress);
mail.To.Add(FilePaths.Default.Email);
mail.Subject = FilePaths.Default.SquadronNumber + " Gliding Training Return";
mail.Body = "Please find attached todays Training Return from " + FilePaths.Default.SquadronNumber +
". Please do not reply to this email address as its unmonitored. " +
"If you have any questions or require further information please contact the Adj on adj.644vgs#aircadets.org";
mail.Attachments.Add(new Attachment(FilePaths.Default.GlidingTrainingReturnFolder + ("\\Gliding Training Return" + date.ToString("dd-MMM-yyyy") + ".pdf")));
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(FilePaths.Default.SquadronEmailAddress, FilePaths.Default.DatabasePassword);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("Email Sent");
Use the timeout property of the SmtpClient class
SmtpServer.timeout = 200000 ; //change it as needed
specifies the time-out value in milliseconds. The default value is 100,000 (100 seconds).
By the way calling SmtpServer a variable that is actually a SmtpClient is very bad practice
For more details see
this link
You can change the timeout by modifying the SmtpClient.Timeout property. It defaults to 100 seconds, which is already a lot, so if you are really exceeding that, you might want to look for a different solution instead. You could for example upload the attachment somewhere and send a link instead—the recipient will thank you too.
How can I attach a file to this mailto string?
string mailto = "mailto:" + to + "&SUBJECT=" + subject + "?BODY=" + body +
"&Attachment=" + attachment;
This doesn't work; the file isn't attached.
Remove the quotes at the end of "attachment".
"mailto:" + to + "&SUBJECT=" + subject + "?BODY=" + body + "&Attachment=" + attachment
Where attachment has the attachment link.
Note: This will not work if the users dont have access to the attachment so you can try attaching and sending it through a c# code.
From what I saw on the web (and by trying it to), it is not always possible to do so. Some email client, and by some I mean lots of them, will not let you do this because it is considered a security hole. However, when it is accepted, the syntax provided by Shodan looks good.
Try this
var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = string.Format("\"{0}\"", Process.GetProcessesByName("OUTLOOK")[0].Modules[0].FileName);
proc.StartInfo.Arguments = string.Format(" /c ipm.note /m {0} /a \"{1}\"", "someone#somewhere.com", #"c:\attachments\file.txt");
proc.Start();