Jump to content

[Resolvido] Paste image and send via email


startuga
 Share

Recommended Posts

Boa tarde,

Tenho estado a tentar colar imagens e enviar por emial através do VB, mas nao estou a conseguir, quando envio não recebo a imagem mas sim um conjunto enorme de varios caracteres.

Posto isto gostaria de saber se é realmente possivel colar e enviar imagens via email atraves do VB.

Obrigado : )

Link to comment
Share on other sites

De momento é isto que tenho


Imports Microsoft.Office


Public Class Form1
Dim sFilesource As String
Dim sName As String

Private Sub setEmailSend(sSubject As String, sBody As String, _
						 sTo As String, sCC As String, _
						 sFilename As String, sDisplayname As String)
	Dim oApp As Interop.Outlook._Application
	oApp = New Interop.Outlook.Application

	Dim oMsg As Interop.Outlook._MailItem
	oMsg = oApp.CreateItem(Interop.Outlook.OlItemType.olMailItem)

	oMsg.Subject = sSubject
	oMsg.Body = sBody

	oMsg.To = sTo
	oMsg.CC = sCC


	Dim strS As String = sFilename
	Dim strN As String = sDisplayname
	If sFilename <> "" Then
		Dim sBodyLen As Integer = Int(sBody.Length)
		Dim oAttachs As Interop.Outlook.Attachments = oMsg.Attachments
		Dim oAttach As Interop.Outlook.Attachment

		oAttach = oAttachs.Add(strS, , sBodyLen, strN)

	End If

	oMsg.Send()
	MessageBox.Show("Email Send", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

	txtBody.Rtf = ""
	txtTo.Text = ""
	txtCC.Text = ""
	txtFile.Text = ""
	txtSubject.Text = ""

	KillOutLookProcess()

End Sub

Private Sub KillOutLookProcess()
	Try
		Dim Xcel() As Process = Process.GetProcessesByName("OUTLOOK")
		For Each Process As Process In Xcel
			Process.Kill()
		Next
	Catch ex As Exception
	End Try
End Sub
Public Function AppPath()
	Return System.AppDomain.CurrentDomain.BaseDirectory
End Function

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
	If txtTo.Text <> "" Then
		setEmailSend(txtSubject.Text, txtBody.Rtf, txtTo.Text, txtCC.Text, sFilesource, sName)
	Else
		MessageBox.Show("No Recipient", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
	End If
End Sub
End Class
Edited by startuga
Link to comment
Share on other sites

Diz-me uma coisa tu queres adicionar a imagem como anexo ou queres mesmo colar no body e ao abrir mostra logo?

No caso de ser como anexo pelo teu código não vejo nada de anormal. Se for para por no body tens de configurar o email do tipo html e tens de editar de forma a que tenha o seguinte código:

<img src="cid:nomedaimagem.jpg" alt="img1">

A imagem terá de estar em anexo e o cid terá de ter exactamente o mesmo nome como está no anexo.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.