Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data can be sent from cells, for example C2:H5, and the recipient receives a letter with the rows arranged like this:
how they are located and at the sender, and not in one line.
Thank you. - Sub Send_Mail()
-
Const CDO_Cnf = "http://schemas.microsoft.com/cdo/configuration/"
-
Dim oCDOCnf As Object, oCDOMsg As Object
-
Dim SMTPserver As String, sUsername As String, sPass As String, sMsg As String
-
Dim sTo As String, sFrom As String, sSubject As String, sBody As String, sAttachment As String
-
On Error Resume Next
-
'sFrom - как правило совпадает с sUsername
-
SMTPserver = [B10] ' SMTPServer: для Mail.ru "smtp.mail.ru"; для Яндекса "smtp.yandex.ru"; для Рамблера "mail.rambler.ru"
-
sUsername = [B11] ' Учетная запись на сервере
-
sPass = [B12] ' Пароль к почтовому аккаунту
-
-
If Len(SMTPserver) = 0 Then MsgBox "Не указан SMTP сервер", vbInformation, "www.Excel-VBA.ru": Exit Sub
-
If Len(sUsername) = 0 Then MsgBox "Не указана учетная запись", vbInformation, "www.Excel-VBA.ru": Exit Sub
-
If Len(sPass) = 0 Then MsgBox "Не указан пароль", vbInformation, "www.Excel-VBA.ru": Exit Sub
-
-
sTo = [B2] 'Кому
-
sFrom = [B3] 'От кого
-
sSubject = [B4] 'Тема письма
-
sBody = [B5] 'Текст письма
-
sAttachment = [B6] 'Вложение(полный путь к файлу)
-
-
'Назначаем конфигурацию CDO
-
Set oCDOCnf = CreateObject("CDO.Configuration")
-
With oCDOCnf.Fields
-
.Item(CDO_Cnf & "sendusing") = 2
-
.Item(CDO_Cnf & "smtpauthenticate") = 1
-
.Item(CDO_Cnf & "smtpserver") = SMTPserver
-
'если необходимо указать SSL
-
'.Item(CDO_Cnf & "smtpserverport") = 465 'для Яндекса и Gmail 465
-
'.Item(CDO_Cnf & "smtpusessl") = True
-
'=====================================
-
.Item(CDO_Cnf & "sendusername") = sUsername
-
.Item(CDO_Cnf & "sendpassword") = sPass
-
.Update
-
End With
-
'Создаем сообщение
-
Set oCDOMsg = CreateObject("CDO.Message")
-
With oCDOMsg
-
Set .Configuration = oCDOCnf
-
.BodyPart.Charset = "koi8-r"
-
.From = sFrom
-
.To = sTo
-
.Subject = sSubject
-
.TextBody = sBody
-
'Проверка наличия файла по указанному пути
-
If Len(sAttachment) > 0 Then
-
If Dir(sAttachment, 16) <> "" Then
-
.AddAttachment sAttachment
-
End If
-
End If
-
.Send
-
End With
-
-
Select Case Err.Number
-
Case -2147220973: sMsg = "Нет доступа к Интернет"
-
Case -2147220975: sMsg = "Отказ сервера SMTP"
-
Case 0: sMsg = "Письмо отправлено"
-
Case Else: sMsg = "Ошибка номер: " & Err.Number & vbNewLine & "Описание ошибки: " & Err.Description
-
End Select
-
MsgBox sMsg, vbInformation, "www.Excel-VBA.ru"
-
Set oCDOMsg = Nothing: Set oCDOCnf = Nothing
-
End Sub
-
-
'---------------------------------------------------------------------------------------
-
' Procedure : Get_File_Path
-
' Purpose : Процедура выбора файла
-
'---------------------------------------------------------------------------------------
-
Sub Get_File_Path()
-
Dim sPath
-
sPath = Application.GetOpenFilename("All Files(*.*),*.*", , "Выбрать файлы", "Выбрать", False)
-
If sPath = False Then Exit Sub
-
[B6] = sPath
-
End Sub
0 11265 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: >>Shailesh |
last post by:
hi,
my script(IMAP email client) is sending mail using imap_mail()
function.
imap_mail($To, $Subject, $Body, $headers);
$headers = "From: <$From>\n";
$headers .= "X-Sender: <$U@$DOMAIN>\n";
|
by: HoustonComputerGuy |
last post by:
I am working on getting my web applications moved to .Net 2.0 and am
having some problems with System.Net.Mail. I get the following error
when sending the mail:
System.Net.Mail.SmtpException was unhandled by user code
Message="Failure sending mail."
Source="System"
StackTrace:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at...
|
by: at |
last post by:
Hi,
I need to test a mail function through my IPS, who doesn't allow sending
mail without a password. Where do I specify this password? In php.ini I
can specify SMTP and sender, but apparently not password.
Jakob
|
by: HK |
last post by:
In VB.NET, I'm getting the exception "failure sending mail". I'm running VS
2005 on XP Home. This is a new install on a new PC. I've never had email
problems with VS 2003, and there I could modify the SMTP settings in IIS.
But with this install, there is no IIS (at least I can't find an IIS with
MMC browsing the snap-ins). I suspect that...
|
by: Zile |
last post by:
I am trying to send mail from web page in asp.net 2.0/VB 2005:
Dim Poruka As New System.Web.Mail.MailMessage
myMessage.From = "matematic@gmail.com"
myMessage.To = "matematic@hotmail.com"
myMessage.Subject = "Automatic sending mail"
myMessage.Body = "Success!"
Mail.SmtpMail.Send(myMessage)
| |
by: mkadasi |
last post by:
Hello Everyone,
I facing a problem in sending mail through vb.net.
The code written below sends the mail to the respective person specified in the 'TO' address. But the problem is that the recipient recieves the mail in Spam.
Can anybody help me out.
Dim mail1 As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
...
|
by: satnamsarai |
last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail.
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.' Not sure how to
fix this error.
I am able to send messages sometimes both other times randomly
following error appear
EXCEPTION:
|
by: Danny |
last post by:
Hi all,
Trying to send mail with System.Net.SmtpClient, using very simple code
just for testing:
SmtpClient smtp = new SmtpClient("mail.server.com", 25);
smtp.Credentials = new
System.Net.NetworkCredential("user", "password");
try
{
|
by: JoeP |
last post by:
Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False
oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient
oSMTP.Send(oMailMessage) (in this line I am getting the above err)
|
by: TanuLamba15 |
last post by:
Hi All,
Can anyone guide me I want to send attachment with my mail and I'm using http://demo.tutorialzine.com/2013/05/mini-ajax-file-upload-form/ plugin instead of simple <input type="file"/>, the issue is occurring when I'm sending mail using above given plugin I'm not receiving attachment and when I'm simply put <input type="file"/> it works...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |