Right I am stumped as hell and I don't even know what I am doing is right. I have some Base64 code of an image which I am emailing using Visual Basic (codes below) but when I recive the email its just shows the box and red cross.
My knowlage is very slim on this and I have just hacked this together. I could be doing something fundamentily stupid but I would not be aware of it.
Please advise :S
VB Code
Public Sub Main()
Dim mySmtpClient As SmtpClient
Dim myMessage As MailMessage
Dim FileReader As StreamReader
Dim EmailBody As String
FileReader = New StreamReader("D:\Extracts\Body.html")
EmailBody = FileReader.ReadToEnd()
myMessage = New MailMessage("eg#example.com", "eg#example.com")
myMessage.Body = EmailBody
myMessage.IsBodyHtml = True
mySmtpClient = New SmtpClient("Server")
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
mySmtpClient.Send(myMessage)
Dts.TaskResult = ScriptResults.Success
End Sub
Body.html
<img src="data:image/jpg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABVAAD/4QNtaHR0cDov
L25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENl
aGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4
OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6
MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5
OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHht
bG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0i
aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1w
PSJodHRwOi8vbnMuYWR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hMCEut
CUwI6FGrTF0rbrwkKC9KgolGoKJQqCiUKgolBelQiUC6VCIKBdKhGEZVCIKBdaFGEZdK/IgjOhRh
GfvUIwjLpUIwiP3oSjCM6gowiL3oSjCMutQmBEXShRhEfvQowiPrUFMCIulCUwIj96gowiP3oSmB
EdCjCI6EpgQnUJgRHQpgQnQpgRH71BTAic96FGELnvQpoRHQowhOhTAiOhKYEJ1CYEJdaEpgR0KN
WmLpW3XhIUF6VBRKNQUShUFEoVBRKC9KhEoF0qEQUC6VCMIyqEQUC60KMIy6V+RBGdCjCM/eoRhG
XSoRhEfvQlGEZ1BRhEXvQlGEZdahMCIulCjCI/ehRhEfWoKYERdKEpgRH71BRhEfvQlMCI6FGER0
JTAhOoTAiOhTAhOhTAiP3qCmBE570KMIXPehTQiOhRhCdCmBEdCUwITqEwIS60JTAjoUa//Z"
/>
Try using a hidden attachment as per .net - embedding attached image in html email
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain")
Dim logo As New LinkedResource(Server.MapPath("images1/links/beach-icon.jpg"))
logo.ContentId = "embeddedimage"
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString("<p>Here is an embedded image.</p> <img src=cid:embeddedimage> <p>More text here</p>", Nothing, "text/html")
htmlView.LinkedResources.Add(logo)
objMM.AlternateViews.Add(plainView)
objMM.AlternateViews.Add(htmlView)
Related
Please suggest me how to achieved this:
The other table having set of data which I need to send:
Now by using SSIS we have to send the set of data to that email. In production I'm having 135 emails and have send them a separate data which contain their set of area.
#pp#gmial.cpm will get only data where subject is maths.
I have no idea to create variable of how to pass variable.
Can any one help me with this?
I use this method a lot for sending emails:
public static void SendEmail(List<string> to, string subject, string body, string filepathName = null)
{
using (MailMessage mail = new MailMessage())
{
string from = ConfigurationManager.AppSettings["EmailFrom"];
SmtpClient SmtpServer = new SmtpClient("your email server");
mail.From = new MailAddress(from);
foreach(string t in to)
mail.To.Add(new MailAddress(t));
mail.Subject = subject;
mail.ReplyToList.Add("your reply to email");
mail.IsBodyHtml = true;
mail.Body = body;
mail.Bcc.Add("enter your email if you want to be copied");
if (filepathName != null)
{
Attachment file;
file = new Attachment(filepathName);
mail.Attachments.Add(file);
}
SmtpServer.Port = 2525; //this is unique to you
SmtpServer.Credentials = new NetworkCredential(from, ConfigurationManager.AppSettings["EmailPassword"]);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
This won't completely solve your problem but will give you option of sending HTML emails straight from SSIS Script task.
You won't be able to use configuration manager, you will need to "hard code" that.
From the string I parsed from Bing's Pic of the Day, I got the info of the pic to be downloaded, let's say today it is /az/hprichbg/rb/PearlHarborWindows_EN-US8565186567, then we will have full URL of the image be like http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1366x768.jpg
Usually Bing has an image of higher resolutions, so I will download the image 1920x1200 too. It's easy with the URL changed to be like http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg, then give the task to a WebClient such as client1.DownloadFile(url, fileName)
The issue here is, some days, the resolution 1920x1200 is not available, and the download URL of this res.(1920x1200) will be re-directed to the URL of the image /sa/simg/hpb/NorthMale_EN-US8782628354_1920x1200.jpg - as default (you can check it).
So my try was a function to get the return/re-directed URL from the input URL:
Public Function GetWebPageURL(ByVal url As String) As String
Dim Request As WebRequest = WebRequest.Create(url)
Request.Credentials = CredentialCache.DefaultCredentials
Return Request.RequestUri.ToString
End Function
and compare to the input URL to see it they are different, but the result was not as expected.
Could anyone let me know the method to check this re-directed URL, like the return URL after we press Enter and wait for the site to load.
Please give me idea to overcome this obstacle. Thank you!
Notes: Some issues related to access rights on different PCs cause me not to use HttpWebRequest, so I prefer the solution not using HttpWebRequest (WebClient or others are better).
With help from #IvanValadares #AlenGenzić, and suggestion of Proxy for HttpWebRequest from #Jimi, I have come to the fair solution, as the below code:
url1 = "http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg"
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url1), HttpWebRequest)
myHttpWebRequest.MaximumAutomaticRedirections = 1
myHttpWebRequest.AllowAutoRedirect = True
Dim defaultProxy As IWebProxy = WebRequest.DefaultWebProxy
If (defaultProxy IsNot Nothing) Then
defaultProxy.Credentials = CredentialCache.DefaultCredentials
myHttpWebRequest.Proxy = defaultProxy
End If
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse, HttpWebResponse)
url2 = myHttpWebResponse.ResponseUri.ToString
Label1.Text = url1
Label2.Text = url2
Use AllowAutoRedirect and check the StatusCode.
var webRequest = (HttpWebRequest)System.Net.WebRequest.Create("http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg");
webRequest.AllowAutoRedirect = false;
using (var response = (HttpWebResponse)webRequest.GetResponse())
{
if (response.StatusCode == HttpStatusCode.Found)
{
// Have been redirect
}
else if (response.StatusCode == HttpStatusCode.OK)
{
// Have not been redirect
}
}
Using HttpClient
var handler = new HttpClientHandler()
{
AllowAutoRedirect = false
};
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = await client.GetAsync("http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg");
if (response.StatusCode == HttpStatusCode.Found)
{
// Have been redirect
}
else if (response.StatusCode == HttpStatusCode.OK)
{
// Have not been redirect
}
With help from #IvanValadares #AlenGenzić, and suggestion of Proxy for HttpWebRequest from #Jimi, I have come to the fair solution as below:
url1 = "http://www.bing.com/az/hprichbg/rb/PearlHarborWindows_EN-US8565186567_1920x1200.jpg"
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url1), HttpWebRequest)
myHttpWebRequest.MaximumAutomaticRedirections = 1
myHttpWebRequest.AllowAutoRedirect = True
Dim defaultProxy As IWebProxy = WebRequest.DefaultWebProxy
If (defaultProxy IsNot Nothing) Then
defaultProxy.Credentials = CredentialCache.DefaultCredentials
myHttpWebRequest.Proxy = defaultProxy
End If
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse, HttpWebResponse)
url2 = myHttpWebResponse.ResponseUri.ToString
Label1.Text = url1
Label2.Text = url2
The System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required. is no longer thrown.
I am working on Adobe Echo sign,I have downloaded the sample code from their website, I am using this sample code for sendingdocument, it has some code missing in sendDocument method so I have changed it. It's giving SoapHeader Exception,with nothing in InnerException,
{"apiActionId=XHZI4WF4BV693YS"}
below is my code of sending document
public static void sendDocument(string apiKey, string fileName, string recipient)
{
ES = new EchoSignDocumentService16();
FileStream file = File.OpenRead(fileName);
secure.echosign.com.FileInfo[] fileInfos = new secure.echosign.com.FileInfo[1];
fileInfos[0] = new secure.echosign.com.FileInfo(fileName, null, file);
SenderInfo senderInfo = null;
string[] recipients = new string[1];
recipients[0] = recipient;
DocumentCreationInfo documentInfo = new DocumentCreationInfo(
recipients,
"Test from SOAP: " + fileName,
"This is neat.",
fileInfos,
SignatureType.ESIGN,
SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED
);
DocumentKey[] documentKeys;
senderInfo = new SenderInfo(recipient, "password", "APIKEY");
documentKeys = ES.sendDocument(apiKey, senderInfo, documentInfo);
Console.WriteLine("Document key is: " + documentKeys[0].documentKey);
}
its giving exception on this line
documentKeys = ES.sendDocument(apiKey, senderInfo, documentInfo);
Can anyone suggest some sample code of Adobe Echo Sign?
On the account page of your login there is an API log you can check. If you check the log entry for your request you may find more information there.
I can't see anything immediately wrong with your code however the EchoSign API guide says that the 'tos' field is deprecated and that the recipients field should be used instead. Helpfully this means you can't use the paramaterised constructor. Try creating your document creation info as such (this is C# but if you need Java it should be straightforward to figure out):
RecipientInfo[] recipientInfo = new RecipientInfo[1];
recipientInfo[0] = new RecipientInfo
{
email = "recipient",
role = RecipientRole.SIGNER,
roleSpecified = true
};
DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo
{
recipients = recipientInfo,
name = "Test from SOAP: " + fileName,
message = "This is neat.",
fileInfos = fileInfos,
signatureType = SignatureType.ESIGN,
signatureFlow = SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED
};
Note that when using the recipientInfo array it seems that the roleSpecified field must be set to true. This little field tripped me up for ages and I was receiving errors similar to yours.
I want to test if a zip has a particular password in vb.net. How can I create a function like check_if_zip_pass(file, pass) As Boolean?
I can't seem to find anything in the .net framework that does this already, unless I'm missing something incredibly obvious.
This method should NOT extract the files, only return True if the attempted pass is valid and False if not.
Use a 3rd party library, like DotNetZip. Keep in mind that passwords in zipfiles are applied to entries, not to the entire zip file. So your test doesn't quite make sense.
One reason WinZip may refuse to unpack the zipfile is that the very first entry is protected with a password. It could be the case that only some entries are protected by password, and some are not. It could be that different passwords are used on different entries. You'll have to decide what you want to do about these possibilities.
One option is to suppose that only one password is used on any entries in the zipfile that are encrypted. (This is not required by the zip specification) In that case, below is some sample code to check the password. There is no way to check a password without doing the decryption. So this code decrypts and extracts into Stream.Null.
public bool CheckZipPassword(string filename, string password)
{
bool success = false;
try
{
using (ZipFile zip1 = ZipFile.Read(filename))
{
var bitBucket = System.IO.Stream.Null;
foreach (var e in zip1)
{
if (!e.IsDirectory && e.UsesEncryption)
{
e.ExtractWithPassword(bitBucket, password);
}
}
}
success = true;
}
catch(Ionic.Zip.BadPasswordException) { }
return success;
}
Whoops! I think in C#. In VB.NET this would be:
Public Function CheckZipPassword(filename As String, password As String) As System.Boolean
Dim success As System.Boolean = False
Try
Using zip1 As ZipFile = ZipFile.Read(filename)
Dim bitBucket As System.IO.Stream = System.IO.Stream.Null
Dim e As ZipEntry
For Each e in zip1
If (Not e.IsDirectory) And e.UsesEncryption Then
e.ExtractWithPassword(bitBucket, password)
End If
Next
End Using
success = True
Catch ex As Ionic.Zip.BadPasswordException
End Try
Return success
End Function
I use SharpZipLib in .NET to do this, here is a link to their wiki with a helper function for unzipping password protected zip files. Below is a copy of the helper function for VB.NET.
Imports ICSharpCode.SharpZipLib.Core
Imports ICSharpCode.SharpZipLib.Zip
Public Sub ExtractZipFile(archiveFilenameIn As String, password As String, outFolder As String)
Dim zf As ZipFile = Nothing
Try
Dim fs As FileStream = File.OpenRead(archiveFilenameIn)
zf = New ZipFile(fs)
If Not [String].IsNullOrEmpty(password) Then ' AES encrypted entries are handled automatically
zf.Password = password
End If
For Each zipEntry As ZipEntry In zf
If Not zipEntry.IsFile Then ' Ignore directories
Continue For
End If
Dim entryFileName As [String] = zipEntry.Name
' to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
' Optionally match entrynames against a selection list here to skip as desired.
' The unpacked length is available in the zipEntry.Size property.
Dim buffer As Byte() = New Byte(4095) {} ' 4K is optimum
Dim zipStream As Stream = zf.GetInputStream(zipEntry)
' Manipulate the output filename here as desired.
Dim fullZipToPath As [String] = Path.Combine(outFolder, entryFileName)
Dim directoryName As String = Path.GetDirectoryName(fullZipToPath)
If directoryName.Length > 0 Then
Directory.CreateDirectory(directoryName)
End If
' Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
' of the file, but does not waste memory.
' The "Using" will close the stream even if an exception occurs.
Using streamWriter As FileStream = File.Create(fullZipToPath)
StreamUtils.Copy(zipStream, streamWriter, buffer)
End Using
Next
Finally
If zf IsNot Nothing Then
zf.IsStreamOwner = True ' Makes close also shut the underlying stream
' Ensure we release resources
zf.Close()
End If
End Try
End Sub
To test, you could create a file compare that looks at the file before it's zipped and again after it has been unzipped (size, date, etc...). You could even compare the contents if you wanted to use a simple test file, like a file with the text "TEST" inside. Lots of choices, depends on how much and how far you want to test.
There's not much built into the framework for doing this. Here's a big sloppy mess you could try using the SharpZipLib library:
public static bool CheckIfCorrectZipPassword(string fileName, string tempDirectory, string password)
{
byte[] buffer= new byte[2048];
int n;
bool isValid = true;
using (var raw = File.Open(fileName, FileMode.Open, FileAccess.Read))
{
using (var input = new ZipInputStream(raw))
{
ZipEntry e;
while ((e = input.GetNextEntry()) != null)
{
input.Password = password;
if (e.IsDirectory) continue;
string outputPath = Path.Combine(tempDirectory, e.FileName);
try
{
using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite))
{
while ((n = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, n);
}
}
}
catch (ZipException ze)
{
if (ze.Message == "Invalid Password")
{
isValid = false;
}
}
finally
{
if (File.Exists(outputPath))
{
// careful, this can throw exceptions
File.Delete(outputPath);
}
}
if (!isValid)
{
break;
}
}
}
}
return isValid;
}
Apologies for the C#; should be fairly straightforward to convert to VB.NET.
This is strange. I've got a WCF Message and I'm trying to read the contents of the body into an XmlDocument. The contents of the message body look like this on the wire (when inspected with WCF tracing turned on):
<abc>
<timeZone>(GMT-05:00) Eastern Time (US & Canada)</timeZone>
</abc>
The code for the reader looks like this:
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = false;
settings.CheckCharacters = false;
XmlReader bodyReader = XmlReader.Create(
message.GetReaderAtBodyContents().ReadSubtree(), settings);
XmlDocument messageDoc = new XmlDocument();
messageDoc.Load(bodyReader);
The resulting XML in messageDoc looks like this:
<abc>
<timeZone>(GMT-05:00) Eastern Time (US &Canada)</timeZone>
</abc>
So where did the extra whitespace after the original & go?
You can simplify the code by removing the XmlReader. Then set the PreserveWhiteSpace on the XmlDocument. You can replace all of your code with:
XmlDocument messageDoc = new XmlDocument() { PreserveWhitespace = true };
messageDoc.Load(message.GetReaderAtBodyContents().ReadSubtree());