AegisImplicitMail asp.net html body email - html

I am trying to send mail in asp.net whit AegisImplicitMail. My code is:
string OggettoEmailIta = "Oggetto email";
string TestoEmailIta = "<p>aaa</p><br/><div>bbb</div>";
var mailMessage = new MimeMailMessage();
mailMessage.Subject = OggettoEmailIta;
mailMessage.IsBodyHtml = true;
mailMessage.Body = TestoEmailIta;
mailMessage.Sender = new MimeMailAddress("XXX", "XXX");
mailMessage.From = new MimeMailAddress("XXX", "XXX");
mailMessage.To.Add(new MimeMailAddress("XXX", "XXX"));
mailMessage.To.Add(new MimeMailAddress("XXX", "XXX"));
var emailer = new SmtpSocketClient();
emailer.Host = "smtp.XXX.XX";
emailer.Port = 465;
emailer.SslType = SslMode.Ssl;
emailer.User = "XXX";
emailer.Password = "XXX";
emailer.AuthenticationMode = AuthenticationType.Base64;
emailer.MailMessage.IsBodyHtml = true;
emailer.MailMessage = mailMessage;
emailer.SendMailAsync();
The mail is sent correctly but it is not in HTML format.
Can someone help me?

you might try string literals "#" for your html message, so all chars are kept
string TestoEmailIta = #"<p>aaa</p><br/><div>bbb</div>";

Related

How can I add an attachment to a MailMessage?

I've got this code that sends a simple email using SmtpClient, MailMessage, and MailAddress objects:
private void EmailMessage(string msg)
{
string TO_EMAIL = "cshannon#proactusa.com";
var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
string userName = windowsIdentity.Name;
string subject = string.Format("Log msg from Report Runner app sent {0}; user was {1}", DateTime.Now.ToLongDateString(), userName);
string body = msg;
var SmtpServer = new SmtpClient(ReportRunnerConstsAndUtils.EMAIL_SERVER);
var SendMe = new MailMessage();
SendMe.To.Add(TO_EMAIL);
SendMe.Subject = subject;
SendMe.From = new MailAddress(ReportRunnerConstsAndUtils.FROM_EMAIL);
SendMe.Body = body;
try
{
SmtpServer.UseDefaultCredentials = true;
SmtpServer.Send(SendMe);
}
}
I also need, though, to attach a file to an email. I was doing it using Outlook like so:
Application app = new Application();
MailItem mailItem = app.CreateItem(OlItemType.olMailItem);
. . .
FileInfo[] rptsToEmail = GetLastReportsGenerated();
foreach (var file in rptsToEmail)
{
String fullFilename = String.Format("{0}\\{1}", uniqueFolder, file.Name);
if (!file.Name.Contains(PROCESSED_FILE_APPENDAGE))
{
mailItem.Attachments.Add(fullFilename);
}
}
mailItem.Importance = OlImportance.olImportanceNormal;
mailItem.Display(false);
...but I need to move away from using Outlook for this. Here the MailItem is a Microsoft.Office.Interop.Outlook.MailItem
How can I add attachments in the simple MailMessage I need to use now?
Setting the Importance is not too important, I don't think, but the Display is something I will need to set for the MailMessage, too.
Easy:
if (!file.Name.Contains(PROCESSED_FILE_APPENDAGE))
{
var attachment = new Attachment(fullFilename);
mailMsg.Attachments.Add(attachment);
}
mailMsg.Priority = MailPriority.Normal;

ASP.Net 2013 MVC 5 insert record and sends email with link to the record just created

I have setup an asp.net MVC project that inserts a record and then grabs the url information to be sent via email of which is a link in the body of the email. I would like to be able to pass the location of the details page with the id of the record if that makes sense? I am just not sure how to capture the full path and the id that I just created in the insert of the record just submitted. Can any one please help me on this. It would be greatly appreciated. This is my code and I need the url and id to be in the body of the email upon submit:
[HttpPost]
public ActionResult NewHire([Bind(Include = "ID,Manager,HR_Emp,Emp_FirstName,Emp_LastName,Emp_StartDate,Emp_OfficeLocation,Emp_Department,Emp_Title")] NewHire newhire)
{
if (ModelState.IsValid)
{
_entities.NewHires.Add(newhire);
_entities.SaveChanges();
MailMessage mail = new MailMessage();
mail.To.Add("Stephen.Michaels#brixmor.com");
mail.From = new MailAddress("someone#somewhere.com");
mail.Subject = "Test";
string Body = "<a href=http://www.google.com>" + "Click for Record" + "</a>";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "test";
smtp.Port = 25;
smtp.Send(mail);
return RedirectToAction("NewHire");
}
return View(newhire);
}
I would suggest you to use the Url.Action
if (ModelState.IsValid)
{
_entities.NewHires.Add(newhire);
_entities.SaveChanges();
string url = Url.Action("ActionName", "ControllerName", newhire.id);
MailMessage mail = new MailMessage();
mail.To.Add("Stephen.Michaels#brixmor.com");
mail.From = new MailAddress("someone#somewhere.com");
mail.Subject = "Test";
string Body = "<a href='"+ url +"'>" + "Click for Record" + "</a>";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "test";
smtp.Port = 25;
smtp.Send(mail);
return RedirectToAction("NewHire");
}

php-ews how to set importance when sending an e-mail

I am using php-ews to send mails and I cannot find a way to set the importance (priority) of a mail.
Here is my code:
$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];
$msg = new EWSType_MessageType();
if($to && count($to) > 0){
$toAddresses = $this->getAddresses($to);
$msg->ToRecipients = $toAddresses;
}
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = $subject;
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $this->ews->CreateItem($msgRequest);
return $response;
Thank you in advance for your response!
You need to load the EWSType_ImportanceChoicesType class. Your code should look like this:
$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];
$msg = new EWSType_MessageType();
if($to && count($to) > 0){
$toAddresses = $this->getAddresses($to);
$msg->ToRecipients = $toAddresses;
}
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
$msg->Subject = $subject;
$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;
$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$msgRequest->Items->Message = $msg;
// Start importance code
$msgRequest->Items->Message->Importance = new EWSType_ImportanceChoicesType();
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;
// End importance code
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;
$response = $this->ews->CreateItem($msgRequest);
return $response;
To change the importance just change the ending of the following line to have HIGH, LOW or NORMAL:
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;
I'm not realy familiar with php, but if I'm using C# the mailmessage-class has a "Importance" property which is an enum and can be set to: High, Low and Normal. Default is "Normal".
Hope this helps you...

HTTPService: What is its send method doing?

I've got a JSON string:
query = {"action":"do","password":"c","name":"s"}
When using HTTPService's send method:
_service = new HTTPService();
_service.url = "http://localhost:8080";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
var _request:Object = new Object();
_request.query = query;
_service.request = _request;
_service.send();
I don't know what I am doing wrong but on my HTTP server I get:
{["object","Object"]}
Any clues please?
Thanks
You are declaring an object of an object.
Try:
_service.request = query;
_service.send();
you get
{["object","Object"]}
because of this
var _request:Object = new Object();
_request.query = query;
_service.request = _request;
do this
var jsonOBJ:Object = {};
jsonOBJ.action = "do";
jsonOBJ.password = "c";
jsonOBJ.name = "s";
var _service:HTTPService = new HTTPService();
_service.url = "http://localhost:8080";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
_service.send( JSON.encode( jsonOBJ ) );// encode the json object with AS3Corelib
Don't forget top JSON decode the string on the server side.

subscription in reporting services

I want to subscribe report on specific schedule in reporting services 2008. i.e report will dilever to user automatically on schedule. I am using visual studio 2008. I have done the configuration setting (rsreportserver.config, app.config after adding refrences of asmx files) by refrence msdn. The code is running fine (no exception occur) and I also get subscription id through calling create subscription indicate all going fine. But after running the code no entry made in Subscription table of ReportServer database. And also not get any mail. While through report server web tool, I can get email and also entery made in database but not from coe. Please someone help me. What I am missing. Plz help
Code is given follow: (Keep in mind, I am using VS2008)
void SendReportEmail()
{
RSServiceReference.ReportingService2005SoapClient rs=new RSServiceReference.ReportingService2005SoapClient();
rs.ClientCredentials.Windows.AllowedImpersonationLevel = new System.Security.Principal.TokenImpersonationLevel();
string batchID = string.Empty;
RSServiceReference.ServerInfoHeader infoHeader = rs.CreateBatch(out batchID);
BatchHeader bh = new BatchHeader()
{
BatchID = batchID,
AnyAttr = infoHeader.AnyAttr
};
string report = "/PCMSR6Reports/PaymentRequestStatusMIS";
string desc = "Send email from code to Hisham#comsoft.com";
string eventType = "TimedSubscription";
string scheduleXml="<ScheduleDefinition xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><StartDateTime xmlns=\"http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices\">2010-03-06T15:15:00.000+05:00</StartDateTime></ScheduleDefinition>";
RSServiceReference.ParameterValue[] extensionParams = new RSServiceReference.ParameterValue[7];
extensionParams[0] = new RSServiceReference.ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "Hisham#comsoft.com";
extensionParams[1] = new RSServiceReference.ParameterValue();
extensionParams[1].Name = "IncludeReport";
extensionParams[1].Value = "True";
extensionParams[2] = new RSServiceReference.ParameterValue();
extensionParams[2].Name = "RenderFormat";
extensionParams[2].Value = "MHTML";
extensionParams[3] = new RSServiceReference.ParameterValue();
extensionParams[3].Name = "Subject";
extensionParams[3].Value = "#ReportName was executed at #ExecutionTime";
extensionParams[4] = new RSServiceReference.ParameterValue();
extensionParams[4].Name = "Comment";
extensionParams[4].Value = "Here is your test report for testing purpose";
extensionParams[5] = new RSServiceReference.ParameterValue();
extensionParams[5].Name = "IncludeLink";
extensionParams[5].Value = "True";
extensionParams[6] = new RSServiceReference.ParameterValue();
extensionParams[6].Name = "Priority";
extensionParams[6].Value = "NORMAL";
RSServiceReference.ParameterValue[] parameters = new RSServiceReference.ParameterValue[10];
parameters[0] = new RSServiceReference.ParameterValue();
parameters[0].Name = "BranchId";
parameters[0].Value = "1";
parameters[1] = new RSServiceReference.ParameterValue();
parameters[1].Name = "UserName";
parameters[1].Value = "admin";
parameters[2] = new RSServiceReference.ParameterValue();
parameters[2].Name = "SupplierId";
parameters[2].Value = "0";
string matchData = scheduleXml;
RSServiceReference.ExtensionSettings extSettings = new RSServiceReference.ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";
try
{
string sub="";
RSServiceReference.ServerInfoHeader SubID = rs.CreateSubscription(bh, report, extSettings, desc, eventType, matchData, parameters, out sub);
rs.FireEvent(bh, "TimedSubscription", sub);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
Detail response will be highly appricated.
Try adding # at the beginning of your xml string #"