How can I implement email functionality, where:
When I click on an asp button, a new email window opens with all the content already added from code behind( including To address, From address, Subject and Body).
But the email should not be sent automatically. It requires user to click send button.
The purpose is, admin can modify the email content before sending to users.
Has anyone worked on similar functionality and can help or give me idea on how to implement it ?
Outlook.Application outlookApp = new Outlook.Application ();
Outlook._MailItem mailItem = (Outlook._MailItem)outlookApp.CreateItem ( Outlook.OlItemType.olMailItem );
mailItem.To = address;
// body, bcc etc...
mailItem.Display ( true );
I think you do not need ASP.NET for this. All you need is mailto with the right parameters.
Example:
<a href="mailto:someone#example.com?Subject=Hello%20again&body=This%20is%20body">
Send Mail</a>
This will send email to someone#example.com with subject "Hello" and body "This is body". You can also use CC parameter to add CC emails.
More info on this link
A related question that may help How do I properly encode a mailto link?
Related
I'm trying to launch the email app from the user click some hyper link, I want to add also attachment, the only thing that worked was this link
enter link description here, but now I don't want to specify the MailMessage.From field, I want it to be like when you click on mailto: link, it opens your deafault account or ask you to login, etc.., but whenever I try to set the mailMessage.From = new MailAddress("");, it throws exception, it should be an email
to get my app launch the mail with attachment, now how can I remove the field "From" and let the user use his mail or something like when you use mailto:
if I remove this line, it throws exception
mailMessage.From = new MailAddress();
If you want your WPF application to send an e-mail directly you should use the SmtpClient Class MSDN.
If you are trying to launch the default mail app (like outlook) to send the e-mail, I'd use Process.Start as one of the answers to the question linked specified.
var url = "mailto:user#domain.com";
// var url = "mailto:?subject=aSubject&body=aBody";
// var url = "mailto:?subject=aSubject&body=aBody&attachment=aFile";
Process.Start(url);
I am working on windows application for email sending.
For text formatting i used tinymce editor for email body.
Used tinymce insert image functionality for adding image in email body but when email is sent to user. Images does not appear in user email body.
Then i tried to add base64 image manually as below:
<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAABLCAYAAABk6PuLAAAACXBIWXMAASdHAAEnRwEEDs /'>
Which is failed to load images.
Can we use linked resources and alternate view in tiny mce?
How to load images in email body?
Tiny MCE is just an HTML editor and not a tool which can be used for creating alternate views for email.
Moreover, all email clients don't support inline images (with data URL).
Alternate view is the only way to ensure that all email clients will be able to show your content in the intended manner.
Create a dictionary of linked resources:
Dictionary<string, byte[]> linkedResources = new Dictionary<string, byte[]>();
linkedResources.Add("img1", byte[]);
Create a common method to send email:
public bool SendEmail(Dictionary<string, byte[]> linkedResources)
{
using (SmtpClient mailSender = new SmtpClient("SmtpHost", 22))
{
MailMessage emailMessage = new MailMessage()
{
Subject = "Subject",
SubjectEncoding = Encoding.ASCII,
IsBodyHtml = true,
Body = "Message",
BodyEncoding = Encoding.ASCII,
From = new MailAddress("Sender#domain.com")
};
emailMessage.BodyEncoding = Encoding.ASCII;
emailMessage.IsBodyHtml = true;
AlternateView av = AlternateView.CreateAlternateViewFromString(emailMessage.Body, null, MediaTypeNames.Text.Html);
foreach (var item in linkedResources)
{
MemoryStream streamBitmap = new MemoryStream(item.Value);
var linkedResource = new LinkedResource(streamBitmap, MediaTypeNames.Image.Jpeg);
linkedResource.ContentId = item.Key;
av.LinkedResources.Add(linkedResource);
}
emailMessage.AlternateViews.Add(av);
mailSender.Send(emailMessage);
return true;
}
}
The real question you need to answer is "what is the best way to insert an image in an email". This is a very broad topic that has been answered many times - a little research should lead you to the most common approaches and their pros/cons:
https://sendgrid.com/blog/embedding-images-emails-facts/
https://www.campaignmonitor.com/blog/how-to/2008/08/embedding-images-in-email/
https://www.quora.com/Whats-the-best-practices-for-embedding-images-into-HTML-emails
there is no best solution for that, you can embed the images or attach them as files or just send them as links.
it depends on your requirements. it actually making image tags and link them to my server to get more analytics like the user had opened the email by loading the image throw a handler and the handler receive logs when the user opened the email and I can know how many users opened that email and so on.
Send grid is great for sending emails and getting analytics out of them because it tracks almost everything related to your email, and you should use Send grid to avoid Spam filters
In my experience the only way to solve this is to store that image on the server where it's publicly accessible and then point the img tag src attribute to that url. You have to understand that the HTML that's used in email is severely restricted to regular HTML.
In my WPFapplication I need to be able to open the default email to send an email with attachment previously scanned.
For the scanner i used WIA and I save the scanned image in jpeg.
For email i has tried the MAILTO as follows
string mail1 = "abc#hotmail.com";
string mail2 = "def#yahoo.it";
string attach = #"C:\bla\bla\bla\file.xlsx";
Process.Start(string.Format("mailto:{0}?subject={1}&body={2}&CC={3}&attachment:{4}"
, mail1, subject, body, mail2,attach));
every thing works unless ATTACHMENT when Process.start opens the default email.
you know something better than mailto? or something that gives the ability to attach files to email?
You can upload that file to a server, get a URL and include it into mailto body as a link.
I want send e-mail with some images in content. I think I must attached this images as attachments to e-mail, but my proble is how can I use attached images in mail content?
CODE WHICH SEND MAIL
WebMail.SmtpServer = "my.smtp.server";
WebMail.Send(
clientEmail,
subject,
"<html><head></head><body><img src='???' /></body></html>",
myEmail,
null,
new List<string> () { "path" },
true
);
What I must write as src ?
Any help would be appreciated.
Also good sample at http://blog.devexperience.net/en/12/Send_an_Email_in_CSharp_with_Inline_attachments.aspx
System.Net.Mail.Message Class :
Sample ;
var msg = new System.Net.Mail.Message();
msg.isHTML=true;
msg.Body ="<img src=\"cid:IMG1CONTENT\">";
Attachment mya = new Attachment("file-path-here");
mya.ContentId="IMG1CONTENT";
msg.Attachments.Add(mya);
You can find more details # http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx
To display the images in email content, one solution is to have an absolute URL. Upload the images to your server and use the abosoluter url as the src attribute value
<img src='http://www.yourdomain.com/youfolder/image.jpg' alt='your image desc'/>
But some email clients will disable external images. So user may need to enable "show images" when propmpted so.
I need to send email with attachment. No problem if I do it by myself, but...
Inside the company I work for, I need to pass through a web service awaiting an email and a body.
I know that the implementation of this service use System.Web.mail.Mailmessage doing probably something like this:
MailMessage mm = new MailMessage();
mm.to = email_;
mm.body = body_;
...
So, is there a way to create a string that'll contain my attachement so I can send it to the web service ?
thx.
--Edition--
I must use a class "TheCompanyMail" that has 2 properties (to,body) and one method (send). This class is a proxy to a webservice. This webservice is the one that really sends the mail.
The problem is that I need to add an attachement to the mail and really don't know how to do it.
Example
File f = MyFuturAttachementFile;
TheComapyMail m = new TheCompanyMail();
m.to = "myCustomer#Company.com"
m.body = "Here is the file you're waiting for:"+f.ToString(); //this of course doesn't work !!!
m.send();
So I'm wondering if I can format the string of the body property to add attachement ?
I'm not sure if I'm right, but in my opinion there is no way to pass attachments by adding them in a string to message body. The main why-not argument is safety. I don't think that Microsoft could allow this class to behave like this...
You can't do it that way, you need to add it to the Attachements property of the MailMessage.
Why don't you store the file somewhere else where they can access it and just send them a link to it instead?
You could create an Html email where the "attachment" is actually link to download the file rather than an actual email attachement.