I created an email in ASP.NET and I want to add a link to the body, but this not a normal url, its a file that is created via byte array and now I want that file to be linkable in my email, but no matter what I do the link is clickable but nothing opens, here is my code:
FileContentResult eventPass = new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
eventPass.FileDownloadName = "preview.pkpass";
message += "<a href='//" + eventPass + "' target='_blank'>Click Here</a>";
AlternateView alternateView = AlternateView.CreateAlternateViewFromString(message, null, MediaTypeNames.Text.Html);
alternateView.LinkedResources.Add(inline);
email.AlternateViews.Add(alternateView);
email.IsBodyHtml = true;
email.Headers.Add("Content-Type", "application/vnd.apple.pkpass");
I know the file is generated correctly because if I return eventPass the file downloads.
Do I need to save eventPass to the server?
Possible answer here:
How to set mime type of application/vnd.apple.pkpass in order to share pass by link or email
Please mark my answer as correct if this has helped you.
Related
I'm trying to send a HTTP POST request in Livecode to a webservice.
This is the code in Livecode:
put 8 into tId
put the text of field "image_text" into tBlop
put tBlop into field "image_text"
put "id=" & tId & "&blop=" & base64Encode(tBlop) & "&pic=" &tBlop into tArgList
post tArgList to URL "http://www.example.com/api_donation/blop2"
put it into tFormResults
The webservice is written in PHP using the Slim framework
$id = $app->request->post('id');
$blop = $app->request->post('blop');
$pic = $app->request->post('pic');
// decode image
$blop = base64_decode($blop);
$db = getDB();
$sql = "INSERT INTO picture (id, blop, pic) VALUES ($id, $blop, $pic)";
$stmt = $db->prepare($sql);
//execute sql statement
$res = $stmt->execute($data);
However when the image is inserted in the db and I try to get it in Livecode, the image stored in the db is not a valid image.
Is the reason for this error the encoding? Do I need to change some settings in the db (e.g. utf-8)?
Thank you for your help!
The properties imageData (binary) or text (ASCII) of an image are livecode properties regarding what is shown on the screen. They aren't bmp, jpg, png or any other format.
If you need to create a valid format, you need the export command.
See http://livecode.wikia.com/wiki/Export
I have a PDF document in the following location on the remote web server:
C:\Domains\Bin\Invoices\1000.pdf
How do I link it? I tried:
string rootPath = Server.MapPath("~");
string path = Path.GetFullPath(Path.Combine(rootPath, "..\\Bin\\Invoices"));
<p>#Html.Raw("<a href='"+ path + "\\" + "1000.pdf'>Original PDF copy</a>")</p>
Without success: the browser tooltip shows me file:///C:/domains/bin/invoices/1000.pdf
Thanks.
EDIT
Solved using Joe suggestion, this way:
public FileResult InvoiceInPdf(string id)
{
string rootPath = Server.MapPath("~");
string path = Path.GetFullPath(Path.Combine(rootPath, "..\\Bin\\Invoices\\"));
return File(path + id + ".pdf", "application/pdf");
}
You can't create a hyperlink to browse to a file at an arbitrary location on the server. Which is a good thing, as the security of your web server would otherwise be compromised.
You should create an Action that streams the file you want by returning a FileResult. Google will provide you with examples of this approach.
Send email with attachment,that attachement will be uploaded in the same FORM where from the mail gets triggered.
BACKGROUND:
i.e. I have an FORM that will take name, address etc details from a FROM. After filling the details user would be allowed to a browse and upload an attachment. Onclicking the Upload button the file will get uploaded to the server.
After doing all of the above action when the users clicks on SUBMIT button in this FROM, it should trigger a email with all the details entered in the FORM and With the uploaded file attached in it.
Now, the problem I am facing is : when I click on UPLOAD button, the file is getting uploaed but all the inputs entered gets disappeared.
Any resolution around this will be appreciated.
N.B: We are not using any free ware like for mail functioanlity. Mail is send by a vbscript function.
below is the logic how i/p fields values are getting captured:
ssr_imo = sql_ship_friendly(request.form("ssr_imo"),10)
ssr_ship_name = sql_ship_friendly(request.form("ssr_ship_name"),100)
ssr_ins_nr = sql_ship_friendly(request.form("ssr_ins_nr"),20)
ssr_ins_date = sql_date_friendly(request.form("ssr_ins_date"),30)
port_name = sql_ship_friendly(request.form("port_name"),50)
ssr_port_id = sql_ship_friendly(request.form("ssr_port_id"),20)
opStat = sql_ship_friendly(request.form("opStat"),20)
subEmail = sql_ship_friendly(request.Form("ssr_sub_email"),200)
subName = sql_ship_friendly(request.Form("ssr_sub_name"),70)
ssr_q2 = validate_q_ssr(request.form("ssr_q2"))
ssr_q3 = validate_q_ssr(request.form("ssr_q3"))
debugNote "<b> TEST = </b>" & ssr_q3
ssr_q4 = validate_q_ssr(request.form("ssr_q4"))
ssr_q5 = validate_q_ssr(request.form("ssr_q5"))
ssr_q6 = validate_q_ssr(request.form("ssr_q6"))
ssr_q7 = validate_q_ssr(request.form("ssr_q7"))
ssr_q8 = validate_q_ssr(request.form("ssr_q8"))
ssr_q9 = validate_q_ssr(request.form("ssr_q9"))
ssr_q10 = validate_q_ssr(request.form("ssr_q10"))
ssr_q11 = validate_q_ssr(request.form("ssr_q11"))
ssr_q12 = validate_q_ssr(request.form("ssr_q12"))
ssr_q13 = validate_q_ssr(request.form("ssr_q13"))
ssr_qa = validate_q_ssr(request.form("ssr_qa"))
ssr_qb = validate_q_ssr(request.form("ssr_qb"))
Once you change your form enctype to "multipart/form-data" you can no longer retrieve input values with Request or Request.Form, you have to use the method/function that is part of the upload component or script that you are using.
For example:
In Persit's AspUpload you use obj.Form("inputName") In ChestySoft's
csASPUpload you use obj.Value("inputName")
(In both cases obj is the name of your upload component object instance and inputName is the name of your form element)
Edit: Using the ASP class you are using for uploading you should use Uploader.Form instead of Request.Form to retrieve input values.
Similar to one of my other questions, but I need clarification.
I have a web application where multiple users will be on at the same time. In the app, an image, which is in one of the app folders, will be drawn on like below, saved, and then added to the image control on the page.
Bitmap image = new Bitmap(Server.MapPath("~") + "/Assets/img/timegrid.jpg");
Graphics graphics = Graphics.FromImage(image);
Pen p = new Pen(Color.Blue, 5);
//draw on image
graphics.DrawLine(p, aPoint, bPoint);
//save new image
image.Save(Server.MapPath("~") + "/Assets/img/newtimegrid.jpg");
imgGrid.ImageUrl = "~/Assets/img/newtimegrid.jpg";
Each user's new image will look different. However, I'm worried that User A will see User B's newtimegrid.jpg instead of his own since every user is saving to the same filename. I've heard of using a generic Image Handler and I've read some of the solutions here, but I still don't understand how to use it, or how to call it if I made one, or if this is even a solution to my problem. Any help would be appreciated.
I would suggest you to keep userID in the session and use this id in the path to uniquely identifying the path of image for each user image path.
You can first check if path already exists for user.
string strDirPath = Server.MapPath("~") + "/Assets/img/ + Session["UserID"].ToString();
if(Directory.Exists(strDirPath))
{
Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
//your code here
}
else
{
DirectoryInfo CreateDirectory(strDirPath);
Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
//your code here
}
So I know how to send emails with attachments... thats easy.
The problem now is I need to add an MailMessage, that has an attachment of its own, to a different MailMessage. This will allow the user to review things and take the email that is pre-made and send it if everything is ok.
I am not sure this will be the final work flow, but I would like to know if easy.
I see a bunch of software out there that is for money, the users getting these emails will be using an outlook client.
This would be deployed to a cheap shared hosting solutions, must be able to run in Meduim Trust!
I would prefer not to have to lic a 3rd party software, No $ :(
Any ideas would be awesome.
MailMessages cannot be attached to other MailMessages. What you will do is create an .msg file, which is basically a file that stores an e-mail and all of its attachments, and attach that to your actual MailMessage. MSG files are supported by Outlook.
For more information about the file extension, go here: http://www.fileformat.info/format/outlookmsg/
As Justin said, there is no facility to attach one MailMessage to another in the API. I worked around this using the SmtpClient to "deliver" my inner message to a directory, and then attached the resulting file to my outer message. This solution isn't terribly appealing, as it has to make use of the file system, but it does get the job done. It would be much cleaner if SmtpDeliveryMethod had a Stream option.
One thing to note, the SmtpClient adds X-Sender/X-Receiver headers for the SMTP envelope information when creating the message file. If this is an issue, you will have to strip them off the top of the message file before attaching it.
// message to be attached
MailMessage attachedMessage = new MailMessage("bob#example.com"
, "carol#example.com", "Attached Message Subject"
, "Attached Message Body");
// message to send
MailMessage sendingMessage = new MailMessage();
sendingMessage.From = new MailAddress("ted#example.com", "Ted");
sendingMessage.To.Add(new MailAddress("alice#example.com", "Alice"));
sendingMessage.Subject = "Attached Message: " + attachedMessage.Subject;
sendingMessage.Body = "This message has a message attached.";
// find a temporary directory path that doesn't exist
string tempDirPath = null;
do {
tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
} while(Directory.Exists(tempDirPath));
// create temp dir
DirectoryInfo tempDir = Directory.CreateDirectory(tempDirPath);
// use an SmptClient to deliver the message to the temp dir
using(SmtpClient attachmentClient = new SmtpClient("localhost")) {
attachmentClient.DeliveryMethod
= SmtpDeliveryMethod.SpecifiedPickupDirectory;
attachmentClient.PickupDirectoryLocation = tempDirPath;
attachmentClient.Send(attachedMessage);
}
tempDir.Refresh();
// load the created file into a stream
FileInfo mailFile = tempDir.GetFiles().Single();
using(FileStream mailStream = mailFile.OpenRead()) {
// create/add an attachment from the stream
sendingMessage.Attachments.Add(new Attachment(mailStream
, Regex.Replace(attachedMessage.Subject
, "[^a-zA-Z0-9 _.-]+", "") + ".eml"
, "message/rfc822"));
// send the message
using(SmtpClient smtp = new SmtpClient("smtp.example.com")) {
smtp.Send(sendingMessage);
}
mailStream.Close();
}
// clean up temp
mailFile.Delete();
tempDir.Delete();