Send HTML email asp - email

I want to add some html in an email. I've tried the following.
vFromName = "someone"
vFromAddress = "someemail"
vTo = "recipient"
vSubject="someSubject"
vBodyofemail = "<html><table><tr><td><b>SomeText</b></td></tr></table></html>"
Call SendMail()
sub SendMail()
'change to address of your own SMTP server
strHost = "mail.internal.rouses.com"
Set Mail = Server.CreateObject("Persits.MailSender")
'enter valid SMTP host
Mail.Host = strHost
'From eMail address
Mail.FromName = vFromName
'From address
Mail.From = vFromAddress
'To eMail address
Mail.AddAddress vTo
'message subject
Mail.Subject = vSubject
'message body
Mail.Body = vBodyOfEmail
Mail.Send
end sub
How can i do this? I've tried Mail.HtmlBody but that doesn't work either. The email is sent but all i see are the tags where the html is.

According to this page you need to set the IsHTML flag to true.
strHTML = "Hello world"
Mail.IsHTML = True
Mail.Body = "<HTML><BODY><CENTER>" & strHTML & "</CENTER></BODY></HTML>"

Try adding this line above the send call.
Mail.IsHTML = true
Without it, the Mail object defaults to standard text and whatever is typed into the Body property will be rendered in the email as text.

Not an answer to your question, but shouldn't all messages include plain text as well? Without plain text, you'll surely get a higher spam score.
(And people like myself prefer to switch to plain text if your HTML/CSS is not rendered well. See Guide to CSS support in email clients (2008), and the list at the Email Standards Project.)

Related

Automate Outlook Emails with Attachments in Excel

I have an Excel spreadsheet with the following 5 columns:
Invoice Number, 2) Company, 3) Primary Email address, 4) Secondary Email address(es), 5) Account Number
I also have a folder that contains invoices. Each invoice has the invoice number in its file name -- i.e., Inv_123456.pdf
I want to build an excel macro that -- when I provide a list of invoice number(s) will:
Open an email -- To: <Primary Contact, Cc: <Secondary contacts, and Bcc: <me,
Put the Invoice Number in the subject, and
Go to the folder containing the invoices and attach the corresponding invoice named InvNo_*.pdf, i.e., InvNo_123456.pdf
This is repeated for each invoice number and the email is displayed for review. *Initially, I want to display the email w/attachment until I am comfortable the macro works as expected.
The path to the folder containing the pre-filled invoices is --
C:\Users\christma-2\OneDrive - OurYear2Win\Documents\Clorodet\Invoice Emails\Attachments\Invoice_*.pdf
Following is the macro I've created so far. I would like to pull the invoice with the corresponding invoice number and attach it to the email.
Sub Send_Email_to_List()
Dim OL As Object, MailSendItem As Object
Dim MsgTxt As String
Set OL = CreateObject("Outlook.Application")
For Each xCell In ActiveSheet.Range(Range("C1"), Range("C" & Rows.Count).End(xlUp))
user_email = xCell.Value
user_subject = "Subject Line for the Email"
user_msg = "Thank You For Submitting this email"
Set MailSendItem = OL.CreateItem(olMailItem)
With MailSendItem
.Subject = user_subject
.Body = user_msg
.To = user_email
.CC = " "
.Bcc = "clorodet20607#aol.com"
'I need help getting the correct attachment, putting the invoice number in the subject, and cc'ing the secondary contacts
.Attachments.Add ("C:\Users\christma-2\OneDrive - OurYear2Win\Documents\Clorodet\Invoice Emails\Attachments\W1\???.pdf")
.Display
End With
Next xCell
Set OL = Nothing
End Sub
Find the corresponding contact's email address -- To: <Primary Contact, Cc: <Secondary contacts, and Bcc: <me,
You can use the CreateRecipient method creates a Recipient object. The name of the recipient; it can be a string representing the display name, the alias, or the full SMTP email address of the recipient. So, there is no need to search for the contact.
Sub ResolveName()
Dim myNamespace As Outlook.NameSpace
Dim myRecipient As Outlook.Recipient
Dim CalendarFolder As Outlook.Folder
Set myNamespace = Application.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev")
myRecipient.Resolve
If myRecipient.Resolved Then
Call ShowCalendar(myNamespace, myRecipient)
End If
End Sub
Sub ShowCalendar(myNamespace, myRecipient)
Dim CalendarFolder As Folder
Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
CalendarFolder.Display
End Sub
You can get a Contact instance by using the following sequence of calls:
recipient.AddressEntry.GetContact()
The Outlook object model supports three main ways of customizing the message body:
The Body property returns or sets a string representing the clear-text body of the Outlook item.
The HTMLBody property of the MailItem class returns or sets a string representing the HTML body of the specified item. Setting the HTMLBody property will always update the Body property immediately. For example:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.
Dim objMail As Outlook.MailItem
'Create e-mail item
Set objMail = Application.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>"
.Display
End With
End Sub
The Word object model can be used for dealing with message bodies. See Chapter 17: Working with Item Bodies for more information.
Note, the MailItem.BodyFormat property allows you to programmatically change the editor that is used for the body of an item.

How can I program a group of conditional emails that are sent in order and one by one?

How can I program a group of conditional emails that are to supposed to be sent one by one, depending on the field of the form the user has selected and also by the order that the users fill it out?
Each user is supposed to get only one email, and the email should arrive in their inbox, and it's also is supposed to be displayed on their screen.
Form example:
Name
Email
Option a, Option b, Option c
Submit
I want to be able to send out 4 emails (or more) for Option a, 4 emails for Option b, 4 emails for Option c.
Example:
Option a - Email 1
Option a - Email 2
Option a - Email 3
Option a -Email 4
Let's say:
User 1 fills out the form and selects Option a, he is supposed to get only Option a - Email 1.
User 2 fills out the form and selects Option b, he is supposed to get only Option b - Email 1.
User 3 fills out the form and selects Option a, he is supposed to get only Option a - Email 2.
And so on...
What would be the easiest way to program this form and make a backend so the admin can just edit the emails and options?
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}

Redemption in MS Access / Outlook (trying to include a separate message file in email)

This code is in MS Access (2010) VBA, using the Redemption library with Microsoft Outlook 2010.
I had this process working before, but we recently had a Citrix upgrade that I guess reset something in my Outlook and now the process no longer works.
I have a folder of .msg files which are basically pre-made email templates with all the proper formatting, images, text, etc.
This is what I was doing before:
Dim outlookApp As Object, namespace As Object
Dim oItem, MyItem
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_dot_msg_file)
'And then there are many calls like this:
MyItem.HTMLBody = Replace(MyItem.HTMLBody, "Dear Person,", "Dear " & name)
'...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
'this next line displays the email, and as of this line, it looks correct
'safeItem.Display
'but as of this line, the issue occurs
safeItem.HTMLBody = "<p>This is an extra message that shows up before the .msg file</p>" & safeItem.HTMLBody
safeItem.Recipients.ResolveAll
safeItem.Send
Now when the email is sent, the .msg contents aren't present at all -- the only thing that shows up is the "extra message" that I prepended to the HTMLBody.
What do I need to change or update? Is this something I need to change in the code, or in my Outlook settings, etc?
Extra: body insertion:
Function insertStringBodyTag(htmlBody As String, stringToInsert As String)
Dim s As String
Dim i As Integer
s = htmlBody
i = InStr(1, s, "<body")
i = InStr(i, s, ">")
s = Left(s, i) & stringToInsert & Right(s, Len(s) - i)
insertStringBodyTag = s
End Function
'Called with safeItem.htmlBody = insertStringBodyTag(safeItem.htmlBody, prefix_string)
You cannot concatenate 2 HTML strings and expect a valid HTML string back - the two must be merged - find the position of the "<body"substring in the original HTML body, then find the positon of the following ">" (this way you take care of the body element with attributes), then insert your HTML string following that ">".

EWS: Find mail by EntryID/ItemID in sent items?

I have the EntryID and ItemID of a mail, how can I using EWS get the mail not knowing if it's in the "Inbox" or "Sent items"?
I've tried this..
Dim ewsID As String = "AAAAAMgC9AZo0nACt4jVCOhhCmcHAF35p973GUpBjIUVAx1CYigAAAAAABEAAF35p973GUpBjIUVAx1CYigAAiwdaBwAAA=="
Dim email As EmailMessage = EmailMessage.Bind(service, New Microsoft.Exchange.WebServices.Data.ItemId(ewsID))
But it doesn't find anything.
Help :)
If you have HexEntryId from PR_EntryId or from Outlook OOM app you need to use convertItem to convert to an EWSid to use eg based on what you posted this should work
String ItemId = "AAAAAMgC9AZo0nACt4jVCOhhCmcHAF35p973GUpBjIUVAx1CYigAAAAAABEAAF35p973GUpBjIUVAx1CYigAAiwdaBwAAA==";
AlternateId HexId = new AlternateId(IdFormat.HexEntryId, BitConverter.ToString(Convert.FromBase64String(ItemId)).Replace("-", ""), "Mailbo#domain.com");
AlternateIdBase Converted = service.ConvertId(HexId, IdFormat.EwsId);
EmailMessage Message = EmailMessage.Bind(service, new ItemId(((AlternateId)Converted).UniqueId));
Cheers
Glen

Message after sending mail asp.net

string Emails = "";
foreach (GridViewRow gr in gvregview.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("Checked");
Label ID = (Label)gr.FindControl("lblEmail");
Label lbl = (Label)gr.FindControl("lblPass");
Label Lblmrno = (Label)gr.FindControl("Lblmrno");
if (chk.Checked == true)
{
SendMail(ID.Text, lbl.Text);
//lblmsg.Text = "Mail Sent to "+Lblmrno.Text;
Response.BufferOutput = true;
puposalda.MailSentResponse = Lblmrno.Text;
//Response.Write("Mail to sent to" + Lblmrno.Text);
System.Threading.Thread.Sleep(500);
}
}
Hi Everybody, i want to send mail to all selected users in gridview and display Message 'Mail sent to the user UserName' for each user. Mail is sent successfully but only last user name is displaying. How to do that. Response.write is working but it is displaying message on the top. But i want to display message at specific location.
Thanks
Thanks
lblmsg.Text += "Mail Sent to "+Lblmrno.Text+", ";
in that case you ADD the text, not replace it.
I want to replace text not append Text. When mail to the first user has been sent successfully. Then message should display on the page. then same for other users.